-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
5.0
-
Fix Understood
-
x86
-
windows_xp
Name: gm110360 Date: 07/02/2004
FULL PRODUCT VERSION :
Microsoft Windows XP [Version 5.1.2600]
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
When TreeMap.compare(...) throws a ClassCastException (for a object that
is not a Comparable), the exception message does report the actual type of
the object but does not report the required type (Comparable).
The exception message should report the required class. This would give
much better error feedback to the user (developer). Also, remember that
the reader of the exception message does not have access to the source
code (and can't check the type to which some expression was cast).
(This is a particular case of the problem with ClassCastException that I
have reported before.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the submitted test case.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A ClassCastException whose message also mentioned type "Comparable"
ACTUAL -
see Error Message(s) section
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.ClassCastException: prototype.Main$Something
at java.util.TreeMap.compare(TreeMap.java:1093)
at java.util.TreeMap.put(TreeMap.java:465)
at java.util.TreeSet.add(TreeSet.java:210)
at prototype.Main.main(Main.java:16)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package prototype;
import java.util.*;
public class Main
{
static class Something
{
} // class Something
public static void main( String[] args )
{
SortedSet<Something> somethings = new TreeSet<Something>();
somethings.add( new Something() );
somethings.add( new Something() );
} // main( ... )
} // class Main
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
In this case, reading the class documention suffices..
However, in general, there isn't any general way to know what type is expected
deep inside library code.
(Incident Review ID: 282318)
======================================================================