Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@apache.org Received: (qmail 43086 invoked from network); 6 Nov 2002 18:20:30 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 6 Nov 2002 18:20:30 -0000 Received: (qmail 9440 invoked by uid 97); 6 Nov 2002 18:21:24 -0000 Delivered-To: qmlist-jakarta-archive-commons-dev@jakarta.apache.org Received: (qmail 9384 invoked by uid 97); 6 Nov 2002 18:21:23 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 9373 invoked by uid 50); 6 Nov 2002 18:21:23 -0000 Date: 6 Nov 2002 18:21:23 -0000 Message-ID: <20021106182123.9372.qmail@nagoya.betaversion.org> From: bugzilla@apache.org To: commons-dev@jakarta.apache.org Cc: Subject: DO NOT REPLY [Bug 14306] New: - NullPointerException in CompareToBuilder X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT . 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: For additional commands, e-mail: