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 created issue -
          Joe Hansche made changes -
          Description Original: 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:

          {noformat}
          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)
          {noformat}

          Example feature:
          {code}
          Feature:

              Background:
                  Given I am in the app

              Scenario:
                  When I do something
                  Then I should see something
          {code}

          Example hooks:
          {code}
          Before do |scenario|
              # Do something.
          end
          {code}

          Produces a JSON output similar to:
          {code}
          [{
            uri: "features/background_before.feature",
            line: 1,
            ...
            elements: [
              {keyword: "Background",
              ...
               before: []
               steps: []
              }
            ]
          }]
          {code}
          New: 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:

          {noformat}
          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)
          {noformat}

          Example feature:
          {code}
          Feature:

              Background:
                  Given I am in the app

              Scenario:
                  When I do something
                  Then I should see something
          {code}

          Example hooks:
          {code}
          Before do |scenario|
              # Do something.
          end
          {code}

          Produces a JSON output similar to:
          {code}
          [{
            uri: "features/background_before.feature",
            line: 1,
            ...
            elements: [
              {keyword: "Background",
              ...
               before: []
               steps: []
              }
            ]
          }]
          {code}

          When locking cucumber to version 2.0.0, and all else remaining the same, the old JSON format is produced:
          {code}
          [{
            uri: "features/background_before.feature,
            ...
            elements: [
              {
                keyword: "Background",
                steps: []
              },
              {
                keyword: "Scenario",
                steps: []
              }
            ]
          }]
          {code}
          Note that it does not even have the {{before}} array at all.
          R. Tyler Croy made changes -
          Workflow Original: JNJira [ 164201 ] New: JNJira + In-Review [ 181548 ]
          Kingdon Barrett made changes -
          Link New: This issue is duplicated by JENKINS-42812 [ JENKINS-42812 ]
          James Nord made changes -
          Assignee Original: James Nord [ teilo ]

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

              Created:
              Updated: