Description
Good day,
This is my first report here, so I'm really sorry if I did not fill in the form right .
I just ran into a bug with the method
public static boolean equals(final CharSequence cs1, final CharSequence cs2).
If one of the object is not the String object, the method use the CharSequenceUtils to check the equality.
The problem is that using Math.max(cs1.length(), cs2.length()) give the max length of the 2 objects. Then 1 of the object throw IndexOutOfBoundsException.
I think it will be better to check the size before using CharSequenceUtils as the method equalsIgnoreCase.
Maybe this code could correct the bug :
if (cs1 == cs2) {
return true;
} else if (cs1 == null || cs2 == null) {
return false;
} else if (cs1.length() != cs2.length()) {
return false;
} else if (cs1 instanceof String && cs2 instanceof String) {
return cs1.equals(cs2);
} else {
return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, cs1.length());
}
Kind regards,
Attachments
Issue Links
- duplicates
-
LANG-1162 StringUtils#equals fails with Index OOBE on non-Strings with identical leading prefix
- Closed