commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COLLECTIONS-265) TreeBag allows uncomparable item to be added, breaking toString
Date Sun, 16 Mar 2008 02:08:24 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12579114#action_12579114
] 

Henri Yandell commented on COLLECTIONS-265:
-------------------------------------------

Returning false because the object was not comparable is not the contract agreed on in the
javadoc: 

     * @return <code>true</code> if the object was not already in the <code>uniqueSet</code>

Stephen - were you implying an Exception be thrown? ie) TreeBag will not allow any class that
is not Comparable?

> 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
>             Fix For: 3.3
>
>         Attachments: TreeBag.pat
>
>
> 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.


Mime
View raw message