Return-Path: Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: (qmail 86628 invoked from network); 19 Sep 2007 13:34:09 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 19 Sep 2007 13:34:09 -0000 Received: (qmail 30103 invoked by uid 500); 19 Sep 2007 13:33:59 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 30048 invoked by uid 500); 19 Sep 2007 13:33:59 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 30039 invoked by uid 99); 19 Sep 2007 13:33:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Sep 2007 06:33:59 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 19 Sep 2007 13:36:02 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id D672E7141ED for ; Wed, 19 Sep 2007 06:33:43 -0700 (PDT) Message-ID: <17903580.1190208823858.JavaMail.jira@brutus> Date: Wed, 19 Sep 2007 06:33:43 -0700 (PDT) From: "David Saff (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (COLLECTIONS-265) TreeBag allows uncomparable item to be added, breaking toString In-Reply-To: <31458998.1189453109578.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/COLLECTIONS-265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12528762 ] David Saff commented on COLLECTIONS-265: ---------------------------------------- I prefer #2, but stated it poorly. I would prefer if the first add of an uncomparable Object raised an exception. The example code above is the current, somewhat odd behavior: add accepts the object the first time, but rejects it the second. I think it should reject it the first time for consistency. I agree that #1 is odd. It is the de facto behavior of java.util.TreeSet: that's not terribly important to me, but if it is to the maintainers, TreeBag could follow the example. > TreeBag allows uncomparable item to be added, breaking toString > --------------------------------------------------------------- > > Key: COLLECTIONS-265 > URL: https://issues.apache.org/jira/browse/COLLECTIONS-265 > Project: Commons Collections > Issue Type: Bug > Components: Bag > Affects Versions: 3.2 > Reporter: David Saff > Priority: Minor > > The following code throws an exception not when the Object is added, but when toString is called: > TreeBag bag = new TreeBag(); > bag.add(new Object()); > bag.toString(); > Trace: > java.lang.ClassCastException: java.lang.Object > at java.util.TreeMap.compare(TreeMap.java:1093) > at java.util.TreeMap.getEntry(TreeMap.java:347) > at java.util.TreeMap.get(TreeMap.java:265) > at org.apache.commons.collections.bag.AbstractMapBag.getCount(AbstractMapBag.java:116) > at org.apache.commons.collections.bag.AbstractMapBag.toString(AbstractMapBag.java:581) > [...] > In a client program, toString should never throw an exception--it makes debugging much harder, for one thing. I believe that TreeBag should defend against the addition of uncomparable objects, so that toString will never throw an exception. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.