Skip to content

Json Formatter in 1.1.3 giving Array Out of Bounds exception #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
joshughes opened this issue Mar 11, 2013 · 11 comments
Closed

Json Formatter in 1.1.3 giving Array Out of Bounds exception #476

joshughes opened this issue Mar 11, 2013 · 11 comments
Assignees

Comments

@joshughes
Copy link

When I run a test with a Before Hook, I am getting an Array out of Bounds exception.

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)

The same feature and hook worked with Cucumber JVM 1.1.1 and Cucumber JVM 1.1.2

When I remove the json format from the scenario, the scenario runs.

@aslakhellesoy
Copy link
Contributor

I suspect this is a regression introduced by ba049aa. Can you create a test that reproduces this?

@joshughes
Copy link
Author

I will try to create a test tonight.

I noticed that the commit you mentioned seemed to go into 1.1.2 which I can run without any issue. So I was thinking it was probably one of the commits in 1.1.3 that caused the regression....

#426

SInce this specifically dealt with the json formater I suspect it is the problem. If I do not use the json formater then the tests run fine and the html report looks good.

Thanks

@joshughes
Copy link
Author

The test has been adjusted to show the issue in this PR

#478

@joshughes
Copy link
Author

The JSONFormmater has no element to add the Before Hook to... since the senario has not beed added yet.

Moving format(formatter)

Before Move

@Override
    public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
        runtime.buildBackendWorlds(reporter);

        runtime.runBeforeHooks(reporter, tagsAndInheritedTags());

        runBackground(formatter, reporter, runtime);
        format(formatter);
        runSteps(formatter, reporter, runtime);

        runtime.runAfterHooks(reporter, tagsAndInheritedTags());
        runtime.disposeBackendWorlds();
    }

After Move

@Override
    public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
        runtime.buildBackendWorlds(reporter);
         format(formatter);
        runtime.runBeforeHooks(reporter, tagsAndInheritedTags());

        runBackground(formatter, reporter, runtime);

        runSteps(formatter, reporter, runtime);

        runtime.runAfterHooks(reporter, tagsAndInheritedTags());
        runtime.disposeBackendWorlds();
    }

in CucumberScenario.java.

This fixes the issue with the JSONFormatter but causes issue in the JUnit Reporter.

So it looks like one of the two will need to be updated to fix the issue.

@aslakhellesoy
Copy link
Contributor

This issue seems related to #447

@gphilipp
Copy link
Contributor

I think we have the same issue at our place, @aslakhellesoy : does this PR fix the bug ?

@MatthiasFraass
Copy link

I had to make a SNAPSHOT-build of cucumber-jvm/gherkin in order to fix our builds. But as we're using the Maven-Release-Plugin, which forbids making releases with SNAPSHOT-dependencies, we can't do legal releases anymore.

When will this bugfix go into a release?

@aslakhellesoy
Copy link
Contributor

This might be related to cucumber/gherkin#252 as well.

@aslakhellesoy
Copy link
Contributor

Isn't this fixed in 1.1.4 and/or 1.1.5-SNAPSHOT?

@brasmusson
Copy link
Contributor

Yes, it is fixed in 1.1.4 (which is showed by the merge of #478).

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants