United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4942830 (coll spec) TreeSet.remove - absence of Compara{ble,tor} throws ClassCastException
JDK-4942830 : (coll spec) TreeSet.remove - absence of Compara{ble,tor} throws ClassCastException

Details
Type:
Enhancement
Submit Date:
2003-10-23
Status:
Resolved
Updated Date:
2012-10-08
Project Name:
JDK
Resolved Date:
2005-09-04
Component:
core-libs
OS:
windows_2000
Sub-Component:
java.util:collections
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
Name: rmT116609			Date: 10/23/2003


A DESCRIPTION OF THE PROBLEM :
The method TreeSet.remove(Object o) throws a ClassCastException if the objects collected in the TreeSet and the Object o doesn't implement Comparable or specify a Comparator. The documentation says: "Throws: ClassCastException - if the specified object cannot be compared with the elements currently in the set." It would be nice, if you could be more specific here and tell the user, that he has to implement Comparable or specify a Comparator. There are lot's of questions about this in your community forums.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Throws: ClassCastException - if the specified object cannot be compared with the elements currently in the set.
  To achieve this implement Comparable or create the TreeSet with a Comparator.
ACTUAL -
Throws: ClassCastException - if the specified object cannot be compared with the elements currently in the set.

URL OF FAULTY DOCUMENTATION :
http://java.sun.com/j2se/1.4.2/docs/api/java/util/TreeSet.html
(Incident Review ID: 217359) 
======================================================================

                                    

Comments
EVALUATION

Will be fixed as part of JSR166 maintenance
###@###.### 2005-03-09 03:11:45 GMT
                                     
2005-03-09
EVALUATION

I don't think we want the precise details in every 
method spec for ClassCastException, but we're providing
somewhat improved documentation throughout the
Collections hierarchy.
                                     
2005-08-22



Hardware and Software, Engineered to Work Together