Maintenance Notice

The bugs.java.com site will be undergoing maintenance on 15th Dec 2017 21:00 PST to 16th Dec 2017 1:00 AM PST.
JDK-4942830 : (coll spec) TreeSet.remove - absence of Compara{ble,tor} throws ClassCastException
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util:collections
  • Affected Version: 1.4.2
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-10-23
  • Updated: 2012-10-08
  • Resolved: 2005-09-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
JDK 6
6 b51Fixed
Related Reports
Relates :  
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 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

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