Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
ClassCastException in paremetrized type (tried with 1.28 and 1.31) #413
I've come across what I think is an issue with generics. Below is a self-contained test that demonstrates the problem. The method test1() runs fine whereas test2() throws a ClassCastException which I think should not happen:
Basically what is happening is this: I am mocking the type Map for these two variables:
It appears to me that when JMockIt initializes these two mocks, it erroneously picks up the type parameters of the first declaration and associates them with both mock instances. It remains in that incorrect state until you configure explicit expectations for the mocks.
If you happen to write a test that doesn't explicitly set a return value (i.e. rely on the default behavior of returning null) you get a class cast exception.
As you can see test2() can be fixed by simply removing the commented out line:
Without this line you get: