FULL PRODUCT VERSION :
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
EXTRA RELEVANT SYSTEM CONFIGURATION :
with eclipse Mars 2
and with apache ant
A DESCRIPTION OF THE PROBLEM :
The ClassCastException is thrown on the same line of code:
Double val = (Double)0.23f;
sometimes with message:
"java.lang.Float cannot be cast to java.lang.Double"
and sometimes with null message
REGRESSION. Last worked in version 6u45
ADDITIONAL REGRESSION INFORMATION:
java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run the code snippet:
public Integer g(Object data)
{
try
{
Double d = (Double)data;
}
catch(ClassCastException ex)
{
if( ex.getMessage() == null )
{
return 1;
}
}
return 0;
}
@Test
public void h()
{
Integer count = 0;
for( Integer idx = 0; idx < 100000; idx++ )
{
// The test
count += g(0.7312345f);
}
System.out.println("Total ClassCastException's with null message: "+count);
}
and notice that much of the times the message in the exception is null
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the counter should be 0
ACTUAL -
88k (out of 100k) were with null message of the ClassCastException
REPRODUCIBILITY :
This bug can be reproduced often.
---------- BEGIN SOURCE ----------
run the code snippet:
public Integer g(Object data)
{
try
{
Double d = (Double)data;
}
catch(ClassCastException ex)
{
if( ex.getMessage() == null )
{
return 1;
}
}
return 0;
}
@Test
public void h()
{
Integer count = 0;
for( Integer idx = 0; idx < 100000; idx++ )
{
// The test
count += g(0.7312345f);
}
System.out.println("Total ClassCastException's with null message: "+count);
}
and notice that much of the times the message in the exception is null
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
workaround is to add -Xint to JVM flags to work in interpreter mode but this slows the processing substantially of course
note that when debugger is attached in eclipse - this phenomenon does not occur - maybe the code is interpreted when debugger is attached...