commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 14306] New: - NullPointerException in CompareToBuilder
Date Wed, 06 Nov 2002 18:21:23 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14306>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=14306

NullPointerException in CompareToBuilder

           Summary: NullPointerException in CompareToBuilder
           Product: Commons
           Version: 1.0 Final
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Lang
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: schloss@visi.com


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;
        }

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message