diff --git a/spring-core/src/main/java/org/springframework/util/StringUtils.java b/spring-core/src/main/java/org/springframework/util/StringUtils.java index 8b61bc01d33..793a084ef04 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -815,7 +815,10 @@ public abstract class StringUtils { * @param array1 the first array (can be {@code null}) * @param array2 the second array (can be {@code null}) * @return the new array ({@code null} if both given arrays were {@code null}) + * @deprecated as of 4.3.15, in favor of manual merging via {@link LinkedHashSet} + * (with every entry included at most once, even entries within the first array) */ + @Deprecated public static String[] mergeStringArrays(String[] array1, String[] array2) { if (ObjectUtils.isEmpty(array1)) { return array2; @@ -824,9 +827,13 @@ public abstract class StringUtils { return array1; } - Set result = new LinkedHashSet(); + List result = new ArrayList(); result.addAll(Arrays.asList(array1)); - result.addAll(Arrays.asList(array2)); + for (String str : array2) { + if (!result.contains(str)) { + result.add(str); + } + } return toStringArray(result); } diff --git a/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java b/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java index 8ccffe38a63..61e996b45dd 100644 --- a/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/StringUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -443,6 +443,7 @@ public class StringUtilsTests { } @Test + @Deprecated public void testMergeStringArrays() { String[] input1 = new String[] {"myString2"}; String[] input2 = new String[] {"myString1", "myString2"};