|
Quick Lists
|
|
Bug ID:
|
4921296
|
|
Votes
|
1
|
|
Synopsis
|
ClassCastException needs more verbose detailMessage
|
|
Category
|
java:runtime
|
|
Reported Against
|
1.3.1
, 1.4.2
|
|
Release Fixed
|
mustang
|
|
State
|
10-Fix Delivered,
request for enhancement
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
4488551
,
4826718
|
|
Submit Date
|
11-SEP-2003
|
|
Description
|
A DESCRIPTION OF THE REQUEST :
ClassCastExceptions do not inform developers as to what the cast conversion attempted was.
JUSTIFICATION :
a more verbose error message in ClassCastException would eliminate the need for developers to add special try-catch code whenever we are debugging these exceptions.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Foo foo = (Foo) "wrong";
java.lang.ClassCastException: java.lang.String cannot be cast to a org.bogus.Foo
ACTUAL -
java.lang.ClassCastException has no message.
---------- BEGIN SOURCE ----------
String s;
try {
s = (String) new Object();
} catch (ClassCastException e) {
if(e.getMessage() == null);
throw new RuntimeException("ClassCastException should be verbose", e);
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Foo foo;
try {
foo = (Foo) obj;
} catch (ClassCastException e) {
throw new RuntimeException(obj.getClass() + " not a " + Foo.class, e);
}
(Incident Review ID: 201870)
======================================================================
xxxxx@xxxxx 10/4/04 15:37 GMT
|
|
Work Around
|
N/A
|
|
Evaluation
|
This is likely a duplicate of bug 4488551.
In jdk1.4.1 and jdk1.4.2, no detail message was provided. As of tiger b26, a
detail message identical to that observed in 1.4 is now provided on solaris
and linux (no testing done on windows):
$ java -version
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b26)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b26, mixed mode)
$ java Test
Exception in thread "main" java.lang.RuntimeException: ClassCastException should be verbose
at Test.main(Test.java:8)
Caused by: java.lang.ClassCastException: java.lang.Object
at Test.main(Test.java:5)
-- xxxxx@xxxxx 2003-10-29
|
|
Comments
|
Submitted On 13-AUG-2004
warnerja
<original code>
if(e.getMessage() == null); // <-- oops!
</original code>
Confusing workaround - that ";" character really goofed it up, didn't it!
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |