Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-29328

NullPointerException parsing a Background section that has a Before hook.

      As of Cucumber 2.0.1 (cucumber-core 1.2.0), the JSON output format has changed. It now adds a before array into the Background element. That causes GherkinCallback.java to crash because it assumes before will only exist for a Scenario:

      ERROR: Build step failed with exception
      java.lang.NullPointerException
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.GherkinCallback.before(GherkinCallback.java:221)
      	at gherkin.JSONParser.before(JSONParser.java:82)
      	at gherkin.JSONParser.parse(JSONParser.java:48)
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.CucumberJSONParser.parse(CucumberJSONParser.java:77)
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.CucumberJSONParser.parse(CucumberJSONParser.java:43)
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.DefaultTestResultParserImpl$ParseResultCallable.invoke(DefaultTestResultParserImpl.java:159)
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.DefaultTestResultParserImpl$ParseResultCallable.invoke(DefaultTestResultParserImpl.java:105)
      	at hudson.FilePath.act(FilePath.java:991)
      	at hudson.FilePath.act(FilePath.java:969)
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.DefaultTestResultParserImpl.parse(DefaultTestResultParserImpl.java:99)
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.CucumberJSONParser.parse(CucumberJSONParser.java:99)
      	at org.jenkinsci.plugins.cucumber.jsontestsupport.CucumberTestResultArchiver.perform(CucumberTestResultArchiver.java:112)
      	at hudson.plugins.templateproject.ProxyPublisher.perform(ProxyPublisher.java:71)
      	at hudson.tasks.BuildStepMonitor$2.perform(BuildStepMonitor.java:32)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.performAllBuildSteps(AbstractBuild.java:726)
      	at hudson.model.Build$BuildExecution.post2(Build.java:185)
      	at hudson.model.AbstractBuild$AbstractBuildExecution.post(AbstractBuild.java:671)
      	at hudson.model.Run.execute(Run.java:1769)
      	at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
      	at hudson.model.ResourceController.execute(ResourceController.java:98)
      	at hudson.model.Executor.run(Executor.java:374)
      

      Example feature:

      Feature:
      
          Background:
              Given I am in the app
      
          Scenario:
              When I do something
              Then I should see something
      

      Example hooks:

      Before do |scenario|
          # Do something.
      end
      

      Produces a JSON output similar to:

      [{
        uri: "features/background_before.feature",
        line: 1,
        ...
        elements: [
          {keyword: "Background",
          ...
           before: []
           steps: []
          }
        ]
      }]
      

      When locking cucumber to version 2.0.0, and all else remaining the same, the old JSON format is produced:

      [{
        uri: "features/background_before.feature,
        ...
        elements: [
          {
            keyword: "Background",
            steps: []
          },
          {
            keyword: "Scenario",
            steps: []
          }
        ]
      }]
      

      Note that it does not even have the before array at all.

          [JENKINS-29328] NullPointerException parsing a Background section that has a Before hook.

          Joe Hansche added a comment -

          The temporary workaround is to lock the cucumber version to 2.0.0 until this is addressed.

          Joe Hansche added a comment - The temporary workaround is to lock the cucumber version to 2.0.0 until this is addressed.

          Antonio Tello added a comment -

          I'm really glad someone has figured out what was causing this problem because I just started running into it a couple weeks ago and could not figure out what was causing it for the life of me.
          After comparing our feature files with your examples, this is the exact problem.

          Unfortunately locking cucumber to 2.0.0 is not feasible for us due to some of the post 2.0.0 functionality we use. I've taken to just putting the Background conditions in each scenario, which, while inconvenient, at least allows us to continue using the cucumber parsing plugin. +1 for a fix.

          Antonio Tello added a comment - I'm really glad someone has figured out what was causing this problem because I just started running into it a couple weeks ago and could not figure out what was causing it for the life of me. After comparing our feature files with your examples, this is the exact problem. Unfortunately locking cucumber to 2.0.0 is not feasible for us due to some of the post 2.0.0 functionality we use. I've taken to just putting the Background conditions in each scenario, which, while inconvenient, at least allows us to continue using the cucumber parsing plugin. +1 for a fix.

          Robert Luebke added a comment -

          Thank you very much for identifying the problem cause and providing a workaround.
          Locking cucumber version 2.0.0 works for me, but I would prefer a fix.

          Robert Luebke added a comment - Thank you very much for identifying the problem cause and providing a workaround. Locking cucumber version 2.0.0 works for me, but I would prefer a fix.

          Luiz Pereira added a comment -

          Hello guys!

          There's any update about this problem?

          Thanks in advance.

          Luiz Pereira added a comment - Hello guys! There's any update about this problem? Thanks in advance.

          Bruno Bossola added a comment -

          Same here, we'd love an update. Unfortunately I cannot lock the cucumber version, and this (blocking / critical) issue is now open since more than a year!

          When in your wiki page you say:
          *Q. *Can I still use the other cucumber plugin.
          *A. *Yes both can work side by side - but why?
          Well, because the other one works!!!

          Bruno Bossola added a comment - Same here, we'd love an update. Unfortunately I cannot lock the cucumber version, and this (blocking / critical) issue is now open since more than a year! When in your wiki page you say: *Q. *Can I still use the other cucumber plugin. *A. *Yes both can work side by side - but why ? Well, because the other one works!!!

          Bruno Bossola added a comment -

          Please note that you have a pull request that you can merge and solves this problem:
          https://github.com/jenkinsci/cucumber-testresult-plugin/pull/9
          I would think about merging it

          Bruno Bossola added a comment - Please note that you have a pull request that you can merge and solves this problem: https://github.com/jenkinsci/cucumber-testresult-plugin/pull/9 I would think about merging it

            Unassigned Unassigned
            jhansche Joe Hansche
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: