Sergi Parpal created LANG-1841:
----------------------------------

             Summary: StrBuilder.equalsIgnoreCase(null) throws 
NullPointerException
                 Key: LANG-1841
                 URL: https://issues.apache.org/jira/browse/LANG-1841
             Project: Commons Lang
          Issue Type: Bug
          Components: lang.text.*
    Affects Versions: 3.22.0, 2.6
            Reporter: Sergi Parpal


The Javadoc of {{StrBuilder.equalsIgnoreCase(StrBuilder)}} says "@param other 
The object to check, null returns false.", but the method throws 
{{NullPointerException}} when {{other}} is {{null}}. {{equals(StrBuilder)}} has 
the same Javadoc and returns {{false}}.

{code:java}
new StrBuilder("a").equals((StrBuilder) null); // false
new StrBuilder("a").equalsIgnoreCase(null);    // NullPointerException
{code}

With 3.22.0 on Java 11:
{noformat}
java.lang.NullPointerException
        at 
org.apache.commons.lang3.text.StrBuilder.equalsIgnoreCase(StrBuilder.java:1904)
{noformat}

*Cause*

The method compares sizes before checking for {{null}}:
{code:java}
if (this == other) {
    return true;
}
if (this.size != other.size) {
    return false;
}
{code}
It has done so since it was added in 2.2.

{{StrBuilder}} is deprecated in favour of Commons Text, where 
{{TextStringBuilder}} and {{StrBuilder}} have the same bug: TEXT-244.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to