java.lang.ClassCastException with null message and cause
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
Copyright License: Author:「E. Levy」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer. Link to:https://stackoverflow.com/questions/40502576/java-lang-classcastexception-with-null-message-and-cause
About “java.lang.ClassCastException with null message and cause” questions
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)
...
|
Today I was working on my program and I got this error.
Caused by:java.lang.ClassCastException: org.cubeville.blocks.CrossedBlockBrush cannot be cast to org.cubeville.blocks.DefaultBlockBrush
My
|
I am trying to set up Dead Letter Queue monitoring for a system. So far, I can get it to be thrown in the DLQ queue without problems when the message consumption fails on the consumer. Now I'm having
|
I'm implementing an MQ producer which will send messages via an OUT Queue. I have the channel, bridge, outbound bean, and the JMS outbound-channel-adapter setup. When I run my test case by sending ...
|
I have a RuntimeException that has no cause (t.getCause() returns null). When my code runs t.initCause(exceptionToAttach), it gives me an IllegalStateException with the message "Can't overwrite cau...
|
I wrote this sample code that I extracted from a library that I'm making because it is causing a java.lang.ClassCastException and I don't understand why. Here's the code:
interface Event
data class
|
Is there a way when using AssertJ agains a method throwing an excetion to check that the message in the cause is equal to some string.
I'm currently doing something like:
assertThatThrownBy(() ...
|
I have a try-catch statement in my code. In my catch block, I am calling e.getMessage() to print the message of the exception. However, e.getMessage keeps returning a null value. Interestingly, whe...
|
Using Twilio , when receiving call always front camera fail to load.
Note : It works fine when calling.
Error Message : Unable to open camera Camera 1, Facing front, Orientation 270:Fail to co...
|
DropdownButton cause null exception as i am passing string variable in value name parameter.
String diseases = "Select a disease";
DropdownButton<String>(
value: diseases,
items:...
|
|
|