I work on a project using Java 8
We have a negative test similar to this:
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);
}
The negative test expects the exception java.lang.ClassCastException with message "java.lang.Float cannot be cast to java.lang.Double" and it sometimes gets null message
I tried to debug it in eclipse but somehow when attached to debugger the exception and message were as expected all the time