You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by e_...@web.de on 2011/08/30 20:08:34 UTC

Bug in StringUtils.equals()

Hi All,

i found a Bug in lang3. This tests are failed:

Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer(""), new StringBuffer("")));
Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer("123"), new StringBuffer("123")));
___________________________________________________________
Schon gehört? WEB.DE hat einen genialen Phishing-Filter in die
Toolbar eingebaut! http://produkte.web.de/go/toolbar

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Bug in StringUtils.equals()

Posted by sebb <se...@gmail.com>.
On 31 August 2011 06:45, Henri Yandell <fl...@gmail.com> wrote:
> On Tue, Aug 30, 2011 at 1:59 PM, sebb <se...@gmail.com> wrote:
>> On 30 August 2011 19:08,  <e_...@web.de> wrote:
>>> Hi All,
>>>
>>> i found a Bug in lang3. This tests are failed:
>>>
>>> Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer(""), new StringBuffer("")));
>>> Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer("123"), new StringBuffer("123")));
>>
>> The CharSequence interface does not define equals(), so only concrete
>> implementations that provide one (such as String) will use anything
>> other than Object.equals().
>>
>> I don't think this is a bug though perhaps the Javadoc could be clearer.
>
> I think a warning in StringUtils.equals that StringBuffer and
> StringBuilder don't implement equals as you'd expect and to call
> toString before calling such would be valuable.
>
> I think it's weird that the JDK doesn't do a real equals, but I don't
> think it's something we should try to fix.

It's a bit odd that StringUtils.equals() accepts CharSequence, but the
code is really only useful for String objects.
Perhaps it was a mistake to change the parameter type...

After all, the class is called StringUtils.

Would it be useful to add a CharSequenceUtils method to compare
CharSequence objects?
Could have equals() and equalsIgnoreCase().
Those would call toString() first.

> Hen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Bug in StringUtils.equals()

Posted by Henri Yandell <fl...@gmail.com>.
On Tue, Aug 30, 2011 at 1:59 PM, sebb <se...@gmail.com> wrote:
> On 30 August 2011 19:08,  <e_...@web.de> wrote:
>> Hi All,
>>
>> i found a Bug in lang3. This tests are failed:
>>
>> Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer(""), new StringBuffer("")));
>> Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer("123"), new StringBuffer("123")));
>
> The CharSequence interface does not define equals(), so only concrete
> implementations that provide one (such as String) will use anything
> other than Object.equals().
>
> I don't think this is a bug though perhaps the Javadoc could be clearer.

I think a warning in StringUtils.equals that StringBuffer and
StringBuilder don't implement equals as you'd expect and to call
toString before calling such would be valuable.

I think it's weird that the JDK doesn't do a real equals, but I don't
think it's something we should try to fix.

Hen

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: Bug in StringUtils.equals()

Posted by sebb <se...@gmail.com>.
On 30 August 2011 19:08,  <e_...@web.de> wrote:
> Hi All,
>
> i found a Bug in lang3. This tests are failed:
>
> Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer(""), new StringBuffer("")));
> Assert.assertTrue(org.apache.commons.lang3.StringUtils.equals(new StringBuffer("123"), new StringBuffer("123")));

The CharSequence interface does not define equals(), so only concrete
implementations that provide one (such as String) will use anything
other than Object.equals().

I don't think this is a bug though perhaps the Javadoc could be clearer.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org