Skip to content
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

NullPointerException from @Before tag #701

Closed
timp21337 opened this issue Apr 3, 2014 · 4 comments
Closed

NullPointerException from @Before tag #701

timp21337 opened this issue Apr 3, 2014 · 4 comments

Comments

@timp21337
Copy link
Contributor

The following is printed from JUnit, though it does not fail the build:
[junit] Testcase: | DefaultUser | allowExplicit | @{censoredLyricsJSON} | took 0 sec
[junit] Caused an ERROR
[junit] null
[junit] java.lang.NullPointerException
[junit] at gherkin.formatter.JSONFormatter.getSteps(JSONFormatter.java:235)
[junit] at gherkin.formatter.JSONFormatter.getCurrentStep(JSONFormatter.java:65)
[junit] at gherkin.formatter.JSONFormatter.getOutput(JSONFormatter.java:253)
[junit] at gherkin.formatter.JSONFormatter.write(JSONFormatter.java:136)
[junit] at cucumber.runtime.Utils$1.call(Utils.java:34)
[junit] at cucumber.runtime.Timeout.timeout(Timeout.java:13)
[junit] at cucumber.runtime.Utils.invoke(Utils.java:30)
[junit] at cucumber.runtime.RuntimeOptions$2.invoke(RuntimeOptions.java:192)
[junit] at com.sun.proxy.$Proxy18.write(Unknown Source)
[junit] at cucumber.runtime.junit.JUnitReporter.write(JUnitReporter.java:71)
[junit] at cucumber.runtime.ScenarioImpl.write(ScenarioImpl.java:64)
[junit] at cucumber.steps.DBUnitHook.logScenarioStart(DBUnitHook.java:54)
[junit] at cucumber.runtime.Utils$1.call(Utils.java:34)
[junit] at cucumber.runtime.Timeout.timeout(Timeout.java:13)
[junit] at cucumber.runtime.Utils.invoke(Utils.java:30)
[junit] at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:59)
[junit] at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:221)
[junit] at cucumber.runtime.Runtime.runHooks(Runtime.java:209)
[junit] at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:199)
[junit] at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
[junit] at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:83)
[junit] at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
[junit] at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
[junit] at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
[junit] at cucumber.api.junit.Cucumber.runChild(Cucumber.java:89)
[junit] at cucumber.api.junit.Cucumber.runChild(Cucumber.java:40)
[junit] at cucumber.api.junit.Cucumber.run(Cucumber.java:94)
[junit]
[junit] Testcase: | DefaultUser | allowExplicit | @{censoredLyricsJSON} | took 0 sec

This was caused by the following:

@before(order = 1)
public void logScenarioStart(Scenario scenario) {
scenario.write("Scenario: " + scenario.getName() + "\n");
}

@kumar-pulabaigari
Copy link

Hi all,
I am also facing same issue. I am using TestNg cucumber.

Here is the trace:-
cucumber.runtime.CucumberException: java.lang.NullPointerException
at cucumber.api.testng.TestNGCucumberRunner.runCukes(TestNGCucumberRunner.java:57)
at com.hom.stepDefinitions.RunCukes.runCukes(RunCukes.java:14)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:645)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: 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(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cucumber.runtime.Utils$1.call(Utils.java:40)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:34)
at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:294)
at com.sun.proxy.$Proxy5.write(Unknown Source)
at cucumber.api.testng.FeatureResultListener.write(FeatureResultListener.java:75)
at cucumber.runtime.ScenarioImpl.write(ScenarioImpl.java:66)
at com.hom.automationDigital.extentReport.ExtentTestManager.write(ExtentTestManager.java:26)
at com.hom.stepDefinitions.StepDefinitionFeature1.before(StepDefinitionFeature1.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at cucumber.runtime.Utils$1.call(Utils.java:40)
at cucumber.runtime.Timeout.timeout(Timeout.java:16)
at cucumber.runtime.Utils.invoke(Utils.java:34)
at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60)
at cucumber.runtime.Runtime.runHookIfTagsMatch(Runtime.java:224)
at cucumber.runtime.Runtime.runHooks(Runtime.java:212)
at cucumber.runtime.Runtime.runBeforeHooks(Runtime.java:202)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:40)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
at cucumber.api.testng.TestNGCucumberRunner.runCukes(TestNGCucumberRunner.java:50)
... 14 more

@brasmusson
Copy link
Contributor

This issue will be fixed when Cucumber-JVM is updated to use Gherkin v4 (#1035), until then do not use before hooks calling write together with the Json Formatter.

@brasmusson
Copy link
Contributor

Now when #1035 has been merged, the 2.0.0-SNAPSHOT version from the master branch (with the groupId io.cucumber), the Json Formatter handles writes from before hooks correctly.

@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

3 participants