diff --git a/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java b/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java index 797499c32..30cb1ee41 100644 --- a/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java +++ b/src/main/java/org/apache/commons/beanutils2/converters/BooleanConverter.java @@ -43,20 +43,6 @@ */ public final class BooleanConverter extends AbstractConverter { - /** - * Copies the provided array, and ensures that all the strings in the newly created array contain only lower-case letters. - *

- * Using this method to copy string arrays means that changes to the src array do not modify the dst array. - *

- */ - private static String[] copyStrings(final String[] src) { - final String[] dst = new String[src.length]; - for (int i = 0; i < src.length; ++i) { - dst[i] = toLowerCase(src[i]); - } - return dst; - } - /** * The set of strings that are known to map to Boolean.TRUE. */ @@ -97,8 +83,8 @@ public BooleanConverter(final Boolean defaultValue) { * @since 1.8.0 */ public BooleanConverter(final String[] trueStrings, final String[] falseStrings) { - this.trueStrings = copyStrings(trueStrings); - this.falseStrings = copyStrings(falseStrings); + this.trueStrings = trueStrings.clone(); + this.falseStrings = falseStrings.clone(); } /** @@ -115,8 +101,8 @@ public BooleanConverter(final String[] trueStrings, final String[] falseStrings) */ public BooleanConverter(final String[] trueStrings, final String[] falseStrings, final Boolean defaultValue) { super(defaultValue); - this.trueStrings = copyStrings(trueStrings); - this.falseStrings = copyStrings(falseStrings); + this.trueStrings = trueStrings.clone(); + this.falseStrings = falseStrings.clone(); } /** @@ -136,20 +122,16 @@ public BooleanConverter(final String[] trueStrings, final String[] falseStrings, @Override protected T convertToType(final Class type, final Object value) throws Throwable { if (Boolean.class.equals(type) || Boolean.TYPE.equals(type)) { - // All the values in the trueStrings and falseStrings arrays are - // guaranteed to be lower-case. By converting the input value - // to lowercase too, we can use the efficient String.equals method - // instead of the less-efficient String.equalsIgnoreCase method. - final String stringValue = toLowerCase(value); + final String stringValue = toString(value); for (final String trueString : trueStrings) { - if (trueString.equals(stringValue)) { + if (trueString.equalsIgnoreCase(stringValue)) { return type.cast(Boolean.TRUE); } } for (final String falseString : falseStrings) { - if (falseString.equals(stringValue)) { + if (falseString.equalsIgnoreCase(stringValue)) { return type.cast(Boolean.FALSE); } } diff --git a/src/test/java/org/apache/commons/beanutils2/converters/BooleanConverterTest.java b/src/test/java/org/apache/commons/beanutils2/converters/BooleanConverterTest.java index 80567e87a..9fe952750 100644 --- a/src/test/java/org/apache/commons/beanutils2/converters/BooleanConverterTest.java +++ b/src/test/java/org/apache/commons/beanutils2/converters/BooleanConverterTest.java @@ -35,10 +35,10 @@ class BooleanConverterTest { @Test void testAdditionalStrings() { - final String[] trueStrings = { "sure" }; - final String[] falseStrings = { "nope" }; + final String[] trueStrings = { "sure", "ναι" }; + final String[] falseStrings = { "nope", "hayır" }; final AbstractConverter converter = new BooleanConverter(trueStrings, falseStrings); - testConversionValues(converter, new String[] { "sure", "Sure" }, new String[] { "nope", "nOpE" }); + testConversionValues(converter, new String[] { "sure", "Sure", "ναι", "Ναι" }, new String[] { "nope", "nOpE", "hayır", "Hayır" }); assertThrows(ConversionException.class, () -> converter.convert(Boolean.class, "true")); assertThrows(ConversionException.class, () -> converter.convert(Boolean.class, "bogus"));