Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0
-
None
-
None
-
Operating System: All
Platform: All
-
14306
Description
CompareToBuilder does not seem to handle nulls well at all.
In the methods:
public CompareToBuilder append(Object lhs, Object rhs)
public CompareToBuilder append(Object[] lhs, Object[] rhs)
If either the lhs or rhs parameters are null, the code is set up to throw a
NullPointerException instead of evaulating on the basis of null. This requires
that all object be vetted before they be placed in a sorting collection, not
using the CompareToBuilder class, modifying the source code, or subclassing
CompareToBuilder. We worked around this by subclassing CompareToBuilder and
overriding the methods in question.
The following lines of code (in both methods) are the cause of the exception:
if (comparison != 0)
{ return this; }if (lhs == rhs) { return this; }
if (lhs == null || rhs == null)
{ throw new NullPointerException(); }The 'if' statement should be replaced with :
if (lhs == null && rhs != null)
{ comparison = -1; return this; }if (lhs != null && rhs == null)
{ comparison = 1; return this; }