Java-8 – always use cube-java8 to get exception “wrong type of constant pool index”
I am designing a sample project for Java 8 dialect My problem is that I didn't get it running I always get the following exception hierarchy:
Tests run: 1,Failures: 0,Errors: 1,Skipped: 0,Time elapsed: 0.068 sec <<< FAILURE! - in soy.wimmer.CucumberIT Feature: Cucumber with Java8 Time elapsed: 0.051 sec <<< ERROR! cucumber.runtime.CucumberException: Failed to instantiate class soy.wimmer.CucumberStepdefs […] Caused by: java.lang.reflect.InvocationTargetException: null […] Caused by: cucumber.runtime.CucumberException: java.lang.IllegalArgumentException: Wrong type at constant pool index […] Caused by: java.lang.IllegalArgumentException: Wrong type at constant pool index at sun.reflect.ConstantPool.getMemberRefInfoAt0(Native Method) at sun.reflect.ConstantPool.getMemberRefInfoAt(ConstantPool.java:47) at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getTypeString(ConstantPoolTypeIntrospector.java:37) at cucumber.runtime.java8.ConstantPoolTypeIntrospector.getGenericTypes(ConstantPoolTypeIntrospector.java:27) at cucumber.runtime.java.Java8StepDeFinition.<init>(Java8StepDeFinition.java:45) at cucumber.runtime.java.JavaBackend.addStepDeFinition(JavaBackend.java:162) at cucumber.api.java8.En.Given(En.java:190) at soy.wimmer.CucumberStepdefs.<init>(CucumberStepdefs.java:8) […] Results : Tests in error: Failed to instantiate class soy.wimmer.CucumberStepdefs Tests run: 1,Skipped: 0
I don't know why I got this mistake or how to solve it
I packed everything in the Maven project The layout is as follows:
./src/test/java/soy/wimmer/CucumberIT.java ./src/test/java/soy/wimmer/CucumberStepdefs.java ./src/test/resources/cucumber/cucumber-java8.feature ./pom.xml
I'm in POM The dependencies contained in XML are:
<dependencies> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-java8</artifactId> <version>1.2.3</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-junit</artifactId> <version>1.2.3</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies>
In addition, POM XML loads only compilers and fail safe plug-ins
My cumberit Java definition:
package soy.wimmer; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions(features = "classpath:cucumber") public class CucumberIT { }
My function definition:
Feature: Cucumber with Java8 As a developer I want to use Cucumber-java8 So that I have nicer step deFinitions Scenario: Let's try it Given I have some dummy code When I try to test it Then it should work with cucumber-java8
This is my step definition:
package soy.wimmer; import cucumber.api.PendingException; import cucumber.api.java8.En; public class CucumberStepdefs implements En { public CucumberStepdefs() { Given("^I have some dummy code$",() -> { // Write code here that turns the phrase above into concrete actions throw new PendingException(); }); When("^I try to test it$",() -> { // Write code here that turns the phrase above into concrete actions throw new PendingException(); }); Then("^it should work with cucumber-java(\\d+)$",(Integer arg1) -> { // Write code here that turns the phrase above into concrete actions throw new PendingException(); }); } }
Any idea what I did wrong here?
resolvent
Solution
This problem is because the cucumber dialect of Java 8 uses the implementation details of Oracle JDK 8
I am using Debian packaged openjdk 8, which leads to constant pools of different organizations When I tried to match Oracle's JDK 8, everything worked as expected
If you want to try it yourself, I'm at GitHub: https://github.com/mawis/cucumber-java8-test The complete sample project is published on
I also reported an error in the cucumber JVM's problem Tracker: https://github.com/cucumber/cucumber-jvm/issues/912
You can check the problem tracker to see if it will fix the problem later
Now, if you want to use cucumber - Java 8, you seem to have to use Oracle's JDK implementation
(the reputation for solving this problem belongs to hoger. I just want to summarize his comments on this problem.)
The above is the whole content of java-8 - always use cube-java8 to obtain the exception "error type of constant pool index" collected and sorted by programming home for you. I hope this article can help you solve the program development problems encountered by java-8 - always use cube-java8 to obtain the exception "error type of constant pool index".
If you think the content of the programming home website is good, you are welcome to recommend the programming home website to programmers and friends.