You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Benedikt Ritter (JIRA)" <ji...@apache.org> on 2015/04/09 14:42:13 UTC
[jira] [Comment Edited] (LANG-1106) StringUtils equals() method
produces wrong result for the below scenario
[ https://issues.apache.org/jira/browse/LANG-1106?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14487303#comment-14487303 ]
Benedikt Ritter edited comment on LANG-1106 at 4/9/15 12:41 PM:
----------------------------------------------------------------
[~naren_k], I don't know what code you're looking at. The current implementation is:
{code:java}
public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
if (cs1 == cs2) {
return true;
}
if (cs1 == null || cs2 == null) {
return false;
}
if (cs1 instanceof String && cs2 instanceof String) {
return cs1.equals(cs2);
}
return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, Math.max(cs1.length(), cs2.length()));
}
{code}
(see https://github.com/apache/commons-lang/blob/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java#L784)
Please make sure you're using the latest release of Commons Lang, which is 3.4 (http://search.maven.org/#artifactdetails%7Corg.apache.commons%7Ccommons-lang3%7C3.4%7Cjar)
was (Author: britter):
[~naren_k], I don't know what code your looking at. The current implementation is:
{code:java}
public static boolean equals(final CharSequence cs1, final CharSequence cs2) {
if (cs1 == cs2) {
return true;
}
if (cs1 == null || cs2 == null) {
return false;
}
if (cs1 instanceof String && cs2 instanceof String) {
return cs1.equals(cs2);
}
return CharSequenceUtils.regionMatches(cs1, false, 0, cs2, 0, Math.max(cs1.length(), cs2.length()));
}
{code}
(see https://github.com/apache/commons-lang/blob/trunk/src/main/java/org/apache/commons/lang3/StringUtils.java#L784)
Please make sure you're using the latest release of Commons Lang, which is 3.4 (http://search.maven.org/#artifactdetails%7Corg.apache.commons%7Ccommons-lang3%7C3.4%7Cjar)
> StringUtils equals() method produces wrong result for the below scenario
> ------------------------------------------------------------------------
>
> Key: LANG-1106
> URL: https://issues.apache.org/jira/browse/LANG-1106
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.*
> Affects Versions: 2.6, 3.3.2
> Environment: java version "1.7.0_02"
> Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
> windows 7
> Reporter: Narendhiran K
> Labels: bug
>
> When we use StringUtils equals() method with below scenario, it returns wrong results.
> Scenario : StringUtils.equals("someStr", null);
> Result : true
> Expected result : false
> Explanation:
> Some logical / typo mistake on the below line.
> return ((str1 == null) ? false : (str2 == null) ? true : str1.equals(str2));
> Instead of "true" it should be "false", when str2 is checked.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)