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

Cucumber JUnit Formatter throws NPE when a Scenario has no steps #774

Closed
bacey opened this issue Sep 12, 2014 · 6 comments
Closed

Cucumber JUnit Formatter throws NPE when a Scenario has no steps #774

bacey opened this issue Sep 12, 2014 · 6 comments

Comments

@bacey
Copy link

bacey commented Sep 12, 2014

I've created a small repo which shows the bug: https://github.com/bacey/cucumber-strict-bug

Cucumber throws a NullPointerException when running --strict on an unimplemented feature.

The command to run is:

./gradlew -PadditionalArgs=--strict cucumber

The result of the above command:

Exception in thread "main" cucumber.runtime.CucumberException: java.lang.NullPointerException
    at cucumber.runtime.formatter.JUnitFormatter.sumTimes(JUnitFormatter.java:176)
    at cucumber.runtime.formatter.JUnitFormatter.done(JUnitFormatter.java:105)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at cucumber.runtime.Utils$1.call(Utils.java:34)
    at cucumber.runtime.Timeout.timeout(Timeout.java:13)
    at cucumber.runtime.Utils.invoke(Utils.java:30)
    at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:172)
    at com.sun.proxy.$Proxy0.done(Unknown Source)
    at cucumber.runtime.Runtime.run(Runtime.java:112)
    at cucumber.api.cli.Main.run(Main.java:36)
    at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.NullPointerException
    at cucumber.runtime.formatter.JUnitFormatter.sumTimes(JUnitFormatter.java:170)
    ... 13 more

FAILURE: Build failed with an exception.

* Where:
Script '/Users/bjuhasz/projects/cucumber-strict-bug/gradle/scripts/cucumber.gradle' line: 37

* What went wrong:
Execution failed for task ':cucumber'.
> Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

System which was used: cucumber-jvm 1.1.8, gradle 2.0, mac.
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

@dkowis
Copy link
Member

dkowis commented Sep 13, 2014

I'll note that it throws the NPE regardless of --strict.

Doesn't seem to be related to --strict usage at all, but the JUnit formatter trying to do sums of things that don't exist.

From your repo:

$  ./gradlew cucumber
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:cucumber
Feature: As a developer I'd like to see a meaningful error message (instead of an NPE)
  when I run cucumber with the --strict paramater and
  when I have an unimplemented feature.

  Scenario: This feature is not yet implemented # NotImplemented.feature:6
    It should fail when using --strict
    It should fail with a meaningful error message when using --strict (and not with a NPE)

Exception in thread "main" cucumber.runtime.CucumberException: java.lang.NullPointerException
        at cucumber.runtime.formatter.JUnitFormatter.sumTimes(JUnitFormatter.java:176)
        at cucumber.runtime.formatter.JUnitFormatter.done(JUnitFormatter.java:105)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at cucumber.runtime.Utils$1.call(Utils.java:34)
        at cucumber.runtime.Timeout.timeout(Timeout.java:13)
        at cucumber.runtime.Utils.invoke(Utils.java:30)
        at cucumber.runtime.RuntimeOptions$1.invoke(RuntimeOptions.java:172)
        at com.sun.proxy.$Proxy0.done(Unknown Source)
        at cucumber.runtime.Runtime.run(Runtime.java:112)
        at cucumber.api.cli.Main.run(Main.java:36)
        at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.NullPointerException
        at cucumber.runtime.formatter.JUnitFormatter.sumTimes(JUnitFormatter.java:170)
        ... 13 more
:cucumber FAILED

FAILURE: Build failed with an exception.

* Where:
Script '/home/dkowis/temp/cucumber-strict-bug/gradle/scripts/cucumber.gradle' line: 37

* What went wrong:
Execution failed for task ':cucumber'.
> Process 'command '/usr/lib/jvm/java-7-openjdk/bin/java'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

@dkowis dkowis changed the title Cucumber throws a NullPointerException when running --strict on an unimplemented feature Cucumber JUnit Formatter throws NPE when there's no implemented steps Sep 13, 2014
@brasmusson
Copy link
Contributor

Lines starting with "It should" are not steps, so the feature file in the repo, contains a Feature with one Scenario with no steps. The NPE is caused by that the Scenario has no step, should the Scenario have unimplemented steps, there would no NPE.

@brasmusson brasmusson changed the title Cucumber JUnit Formatter throws NPE when there's no implemented steps Cucumber JUnit Formatter throws NPE when a Scenario has no steps Sep 14, 2014
brasmusson added a commit that referenced this issue Sep 14, 2014
@bacey
Copy link
Author

bacey commented Sep 15, 2014

Ugh, I'm terribly sorry and ashamed that I wasted your time with such a silly thing. It is totally my fault that I wrote such a syntactically incorrect feature. Sorry again!

@aslakhellesoy
Copy link
Contributor

Don't be sorry @bacey, the exception you got didn't explain much and your bug report helped us improve the general user experience! Cucumber should be able to give better errors rhan that on invalid input. And scenarios without steps aren't even invalid!

@dkowis
Copy link
Member

dkowis commented Sep 18, 2014

Haha! I didn't even notice this! Derp. Sorry about that :|

@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

4 participants