Sergi Parpal created TEXT-244:
---------------------------------
Summary: equalsIgnoreCase(null) throws NullPointerException in
TextStringBuilder and StrBuilder
Key: TEXT-244
URL: https://issues.apache.org/jira/browse/TEXT-244
Project: Commons Text
Issue Type: Bug
Affects Versions: 1.15.0, 1.0
Reporter: Sergi Parpal
The Javadoc of {{TextStringBuilder.equalsIgnoreCase(TextStringBuilder)}} says
"@param other The object to check, null returns false.", but the method throws
{{NullPointerException}} when {{other}} is {{null}}.
{{equals(TextStringBuilder)}} has the same Javadoc and returns {{false}}.
{code:java}
new TextStringBuilder("a").equals((TextStringBuilder) null); // false
new TextStringBuilder("a").equalsIgnoreCase(null); //
NullPointerException
{code}
With 1.15.0 on Java 11:
{noformat}
java.lang.NullPointerException
at
org.apache.commons.text.TextStringBuilder.equalsIgnoreCase(TextStringBuilder.java:1920)
{noformat}
The deprecated {{StrBuilder.equalsIgnoreCase(StrBuilder)}} has the same Javadoc
and fails the same way (StrBuilder.java:1796 in 1.15.0).
*Cause*
Both methods compare sizes before checking for {{null}}:
{code:java}
if (this == other) {
return true;
}
if (this.size != other.size) {
return false;
}
{code}
{{StrBuilder}} has done this since 1.0, and {{TextStringBuilder}} since it was
added in 1.3.
Commons Lang's deprecated {{org.apache.commons.lang3.text.StrBuilder}} has the
same bug; I am reporting it separately in LANG.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)