Never return null from Strings.tokenizeToStringArray (#28224)
This method has a different contract than all the other methods in this class, returning null instead of an empty array when receiving a null input. While switching over some methods from delimitedListToStringArray to this method tokenizeToStringArray, this resulted in unexpected nulls in some places of our code. Relates #28213
This commit is contained in:
parent
0c4e2cbc19
commit
196c7b80dc
|
@ -474,6 +474,9 @@ public class Strings {
|
||||||
* @see #delimitedListToStringArray
|
* @see #delimitedListToStringArray
|
||||||
*/
|
*/
|
||||||
public static String[] tokenizeToStringArray(final String s, final String delimiters) {
|
public static String[] tokenizeToStringArray(final String s, final String delimiters) {
|
||||||
|
if (s == null) {
|
||||||
|
return EMPTY_ARRAY;
|
||||||
|
}
|
||||||
return toStringArray(tokenizeToCollection(s, delimiters, ArrayList::new));
|
return toStringArray(tokenizeToCollection(s, delimiters, ArrayList::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -536,7 +539,7 @@ public class Strings {
|
||||||
*/
|
*/
|
||||||
public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) {
|
public static String[] delimitedListToStringArray(String str, String delimiter, String charsToDelete) {
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
return new String[0];
|
return EMPTY_ARRAY;
|
||||||
}
|
}
|
||||||
if (delimiter == null) {
|
if (delimiter == null) {
|
||||||
return new String[]{str};
|
return new String[]{str};
|
||||||
|
|
|
@ -194,6 +194,14 @@ public class FilterAllocationDeciderTests extends ESAllocationTestCase {
|
||||||
assertEquals("invalid IP address [" + invalidIP + "] for [" + filterSetting.getKey() + ipKey + "]", e.getMessage());
|
assertEquals("invalid IP address [" + invalidIP + "] for [" + filterSetting.getKey() + ipKey + "]", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNull() {
|
||||||
|
Setting<String> filterSetting = randomFrom(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING,
|
||||||
|
IndexMetaData.INDEX_ROUTING_INCLUDE_GROUP_SETTING, IndexMetaData.INDEX_ROUTING_EXCLUDE_GROUP_SETTING);
|
||||||
|
|
||||||
|
IndexMetaData.builder("test")
|
||||||
|
.settings(settings(Version.CURRENT).putNull(filterSetting.getKey() + "name")).numberOfShards(2).numberOfReplicas(0).build();
|
||||||
|
}
|
||||||
|
|
||||||
public void testWildcardIPFilter() {
|
public void testWildcardIPFilter() {
|
||||||
String ipKey = randomFrom("_ip", "_host_ip", "_publish_ip");
|
String ipKey = randomFrom("_ip", "_host_ip", "_publish_ip");
|
||||||
Setting<String> filterSetting = randomFrom(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING,
|
Setting<String> filterSetting = randomFrom(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING,
|
||||||
|
|
Loading…
Reference in New Issue