cucumber-attic / gherkin2

A fast Gherkin parser in Ragel (The parser behind Cucumber)
MIT License
382 stars 221 forks source link

NPE in JSONFormatter in scenario print in a @Before #338

Closed jfbreault closed 8 years ago

jfbreault commented 8 years ago

Sometime, if you writ in scenario in a @Before method

@Before
public void printGridInfo(Scenario scenario){
    seleniumHelperFactory.getScenarioGridInfoPrinter(scenario)
}

stackTrace:

java.lang.NullPointerException
at gherkin.formatter.JSONFormatter.getSteps(JSONFormatter.java:235)
at gherkin.formatter.JSONFormatter.getCurrentStep(JSONFormatter.java:65)
at gherkin.formatter.JSONFormatter.getOutput(JSONFormatter.java:253)
at gherkin.formatter.JSONFormatter.write(JSONFormatter.java:136)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at cucumber.runtime.Utils$1.call(Utils.java:37)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:31)
at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:243)
at com.sun.proxy.$Proxy14.write(Unknown Source)
at cucumber.runtime.junit.JUnitReporter.write(JUnitReporter.java:83)
at cucumber.runtime.ScenarioImpl.write(ScenarioImpl.java:66)
at com.ticketmaster.qa.selenium.commons.v2.helper.scenario.ScenarioHelper.printToggleText(ScenarioHelper.java:29)
at com.ticketmaster.qa.selenium.commons.v2.helper.scenario.ScenarioGridInfoPrinter.printGridInfo(ScenarioGridInfoPrinter.java:59)
at com.ticketmaster.qa.selenium.commons.stepdef.ScenarioInitialyzer.printGridInfo(ScenarioInitialyzer.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at cucumber.runtime.Utils$1.call(Utils.java:37)
at cucumber.runtime.Timeout.timeout(Timeout.java:13)
at cucumber.runtime.Utils.invoke(Utils.java:31)
at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:222)
at cucumber.runtime.Runtime.runHooks(Runtime.java:210)
at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:200)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

The error come from this line that return null https://github.com/cucumber/gherkin/blob/master/java/src/main/java/gherkin/formatter/JSONFormatter.java#L221 Any attempt to write something in scenario in @Before method will throw NPE

brasmusson commented 8 years ago

This would have been fixed by #289. However, it is not the intention to do any more releases of this library (Gherkin2), instead the work is focused on integrating the newly released Gherkin3 library in Cucumber-JVM (and make sure that this issue does not remain then). Therefore I close this issue as duplicate to cucumber/cucumber-jvm#638 that report the same issue on Cucumber-JVM.