ppkarwasz commented on code in PR #364:
URL: https://github.com/apache/commons-beanutils/pull/364#discussion_r2267887859


##########
src/main/java/org/apache/commons/beanutils2/converters/ColorConverter.java:
##########
@@ -90,42 +90,38 @@ protected <T> T convertToType(final Class<T> type, final 
Object value) throws Th
         if (Color.class.isAssignableFrom(type)) {
             final String stringValue = toString(value);
 
-            switch (toLowerCase(stringValue)) {
-            case "black":
+            if (stringValue.equalsIgnoreCase("black")) {
                 return type.cast(Color.BLACK);
-            case "blue":
+            } else if (stringValue.equalsIgnoreCase("blue")) {

Review Comment:
   I think we first need to clarify **what** we’re trying to achieve here, 
because Unicode case-insensitive comparison is not a trivial problem.
   
   If our goal is to support *localized* color names, neither 
`toLowerCase(...)` nor `equalsIgnoreCase(...)` is sufficient for true 
case-insensitive matching.
   
   For example, in German:
   
   ```java
   final String left = "WEISS";
   final String right = "weiß";
   LOGGER.info("Comparing German words: left='{}', right='{}'", left, right);
   
   LOGGER.info("Upper case (Locale.ROOT): left='{}', right='{}'",
           left.toUpperCase(Locale.ROOT),
           right.toUpperCase(Locale.ROOT));
   
   LOGGER.info("Lower case (Locale.ROOT): left='{}', right='{}'",
           left.toLowerCase(Locale.ROOT),
           right.toLowerCase(Locale.ROOT));
   
   LOGGER.info("String.equalsIgnoreCase: {}", left.equalsIgnoreCase(right));
   
   final Collator collator = Collator.getInstance(Locale.ROOT);
   collator.setStrength(Collator.PRIMARY);
   LOGGER.info("Collator (PRIMARY strength): {}", collator.equals(left, right));
   ```
   
   Output:
   
   ```
   Comparing German words: left='WEISS', right='weiß'
   Upper case (Locale.ROOT): left='WEISS', right='WEISS'
   Lower case (Locale.ROOT): left='weiss', right='weiß'
   String.equalsIgnoreCase: false
   Collator (PRIMARY strength): true
   ```
   
   Here, `"weiß"` and `"WEISS"` differ only in case, yet:
   
   * `toLowerCase` fails because it preserves `ß`.
   * `equalsIgnoreCase` fails because it compares per character without case 
folding.
   * Only a full case folding comparison (`Collator` with `PRIMARY` strength) 
treats them as equal.
   
   If we really want proper locale support, we need to use the right tool for 
the job, `Collator`, not just string case transformations.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to