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

StringIndexOutOfBoundsException when no root cause for the build

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Major
    • Resolution: Duplicate
    • Component/s: envinject-plugin
    • Labels:
      None
    • Environment:
      EnvInject 1.91.2
    • Similar Issues:

      Description

      When a build has no root cause (possible when firing the job programmatically), the code at org.jenkinsci.plugins.envinject.service.BuildCauseRetriever#buildCauseEnvironmentVariables produces a StringIndexOutOfBoundsException because the substring method is applied to an empty string.

        Attachments

          Activity

          Hide
          damien_coraboeuf Damien Coraboeuf added a comment -

          There is a pull request at https://github.com/jenkinsci/envinject-plugin/pull/49 to fix this issue.

          Best regards,
          Damien.

          Show
          damien_coraboeuf Damien Coraboeuf added a comment - There is a pull request at https://github.com/jenkinsci/envinject-plugin/pull/49 to fix this issue. Best regards, Damien.
          Hide
          lanwen Kirill Merkushev added a comment -

          A little bit earlier https://github.com/jenkinsci/envinject-plugin/pull/45 - it has tests for it (with some refactoring) + skip of fragile test (the main cause described in pr)

          Show
          lanwen Kirill Merkushev added a comment - A little bit earlier https://github.com/jenkinsci/envinject-plugin/pull/45 - it has tests for it (with some refactoring) + skip of fragile test (the main cause described in pr)
          Hide
          danielbeck Daniel Beck added a comment -

          When a build has no root cause (possible when firing the job programmatically),

          Are you sure you're triggering the build correctly? scheduleBuild etc. all add a cause IIRC.

          Show
          danielbeck Daniel Beck added a comment - When a build has no root cause (possible when firing the job programmatically), Are you sure you're triggering the build correctly? scheduleBuild etc. all add a cause IIRC.
          Hide
          damien_coraboeuf Damien Coraboeuf added a comment - - edited

          Hi Daniel,

          I'm using the following piece of code:

          final AbstractProject job = ...
          List<ParameterValue> parameterValues = ...
          Jenkins.getInstance().getQueue()
                                  .schedule2(
                                          job,
                                          0,
                                          new ParametersAction(parameterValues),
                                          new CauseAction(getCause(channel))
                                  );
          

          where getCause returns a custom cause.

          My initial code in getCause was actually returning an anonymous class for the Cause implementation, and that caused the problem. By replacing the anonymous Cause implementation by a top level class fixed the problem on my side.

          Show
          damien_coraboeuf Damien Coraboeuf added a comment - - edited Hi Daniel, I'm using the following piece of code: final AbstractProject job = ... List<ParameterValue> parameterValues = ... Jenkins.getInstance().getQueue() .schedule2( job, 0, new ParametersAction(parameterValues), new CauseAction(getCause(channel)) ); where getCause returns a custom cause. My initial code in getCause was actually returning an anonymous class for the Cause implementation, and that caused the problem. By replacing the anonymous Cause implementation by a top level class fixed the problem on my side.
          Hide
          danielbeck Daniel Beck added a comment -

          Duplicate of JENKINS-24994, thanks for the hint! I knew I read about anonymous cause subclasses somewhere…

          Show
          danielbeck Daniel Beck added a comment - Duplicate of JENKINS-24994 , thanks for the hint! I knew I read about anonymous cause subclasses somewhere…
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: MerkushevKirill
          Path:
          src/main/java/org/jenkinsci/plugins/envinject/service/BuildCauseRetriever.java
          src/test/java/org/jenkinsci/plugins/envinject/BuildCauseRetrieverTest.java
          http://jenkins-ci.org/commit/envinject-plugin/3d62b4f4505112883d058cab12a86b12e34949dd
          Log:
          JENKINS-28188 fix plugin compatibility with anonymous class cause for build trigger

          • added test for Issue JENKINS-28188
          • fixes exception `StringIndexOutOfBoundsException: String index out of range: -1`
          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: MerkushevKirill Path: src/main/java/org/jenkinsci/plugins/envinject/service/BuildCauseRetriever.java src/test/java/org/jenkinsci/plugins/envinject/BuildCauseRetrieverTest.java http://jenkins-ci.org/commit/envinject-plugin/3d62b4f4505112883d058cab12a86b12e34949dd Log: JENKINS-28188 fix plugin compatibility with anonymous class cause for build trigger added test for Issue JENKINS-28188 fixes exception `StringIndexOutOfBoundsException: String index out of range: -1`
          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Oleg Nenashev
          Path:
          pom.xml
          src/main/java/org/jenkinsci/plugins/envinject/service/BuildCauseRetriever.java
          src/test/java/org/jenkinsci/plugins/envinject/BuildCauseRetrieverTest.java
          src/test/java/org/jenkinsci/plugins/envinject/matchers/WithEnvInjectActionMatchers.java
          http://jenkins-ci.org/commit/envinject-plugin/faea23f93513a83a1bdfddc1eb488a5a295ad195
          Log:
          Merge pull request #45 from lanwen/anonymouse-cause

          [FIXED JENKINS-28188] - Fix for plugin compatibility when used anonymous class cause

          Compare: https://github.com/jenkinsci/envinject-plugin/compare/f6caad427a83...faea23f93513

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Oleg Nenashev Path: pom.xml src/main/java/org/jenkinsci/plugins/envinject/service/BuildCauseRetriever.java src/test/java/org/jenkinsci/plugins/envinject/BuildCauseRetrieverTest.java src/test/java/org/jenkinsci/plugins/envinject/matchers/WithEnvInjectActionMatchers.java http://jenkins-ci.org/commit/envinject-plugin/faea23f93513a83a1bdfddc1eb488a5a295ad195 Log: Merge pull request #45 from lanwen/anonymouse-cause [FIXED JENKINS-28188] - Fix for plugin compatibility when used anonymous class cause Compare: https://github.com/jenkinsci/envinject-plugin/compare/f6caad427a83...faea23f93513

            People

            • Assignee:
              gbois Gregory Boissinot
              Reporter:
              damien_coraboeuf Damien Coraboeuf
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: