Cucumber-jvm 1.1.3 issue with JSON formatter
I have been struggling with a weird cucumber issue today, as it took me some time to figure out what was going on, I thought I’d share this in case somebody is going down the same path.
It started when I decided to upgrade my cucumber-jvm example to the latest version (1.1.3). Quickly after upgrading, I hit that error:
java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.get(ArrayList.java:324)
at gherkin.formatter.JSONFormatter.getFeatureElement(JSONFormatter.java:199)
at gherkin.formatter.JSONFormatter.addHook(JSONFormatter.java:156)
at gherkin.formatter.JSONFormatter.before(JSONFormatter.java:147)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
This is known issue, that has already been fixed in gherkin.
So I rebuilt gherkin locally, thinking it would solve all my problems, and I was still the exact same error, at the same line number. After changing version, deleting the jar from the Maven repository, I was still getting the same error, so it was clear that the class was being pulled from somewhere else.
It turns out the jar was being pulled from cucumber-picocontainer
, which uses shade to create an über-jar with its dependencies, including gherkin. How did I figure that out? Using this piece of code:
URL location = JSONFormatter.class.getProtectionDomain().getCodeSource().getLocation();
System.err.println(location.getPath());
The solution to the problem is therefore to rebuild gherkin, then cucumber-picocontainer, and you’re sorted.
Alternatively you can also just rebuild gherkin, and then make sure it is defined before cucumber-picocontainer
:
<dependency> <groupId>info.cukes</groupId> <artifactId>gherkin</artifactId> <version>2.11.8</version> <scope>test</scope> </dependency> <dependency> <groupId>info.cukes</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>1.1.3</version> <scope>test</scope> </dependency>
Hi,
I encountered similar issue, however couldn’t resolve the problem. Essentially I get gherkin 2.11.8 dependency, and did a clean install.
So what exactly you mean by rebuild gherkin?
Please let me know.
Thanks,
Harsh
— Harsh · 2013-07-25 00:04 · #
Hi Harsh,
To build gherkin:
git clone https://github.com/cucumber/gherkin
cd gherkin/java
mvn install
Current version is 2.12.0, so you’ll need to update the cucumber-jvm pom accordingly.
— sébastien · 2013-07-25 19:24 · #