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(
    at gherkin.formatter.JSONFormatter.getFeatureElement(
    at gherkin.formatter.JSONFormatter.addHook(
    at gherkin.formatter.JSONFormatter.before(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(

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();

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:




  1. 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.


    Harsh · 2013-07-25 00:04 · #

  2. Hi Harsh,

    To build gherkin:

    git clone
    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 · #