Recently I was writing some units tests, as all good developers should, and ran into an issue with a test that made use of the IntStream of(int t) method. The test execution failed and throw the following exception:
java.lang.IllegalStateException: Failed to transform class with name com.readlearncode.ServiceTest. Reason: javassist.bytecode.InterfaceMethodrefInfo cannot be cast to javassist.bytecode.MethodrefInfo
After googling for the solution I found that others had had the same issue. A StackOverflow question and answer gave me the solution. As this is an issue could cause someone quite a lot of pain I thought I would reproduce it below:
PowerMock has a dependency on javassist, exclude the transitive dependency in my POM and include the dependency separately.
Here is the POM snippet:
<dependency> <groupId>org.powermock</groupId> <artifactId>powermock-module-junit4</artifactId> <version>1.6.5</version> <scope>test</scope> <exclusions> <exclusion> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.javassist</groupId> <artifactId>javassist</artifactId> <version>3.20.0-GA</version> <scope>test</scope> </dependency>