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

NPE when checking out a shared library from CVS

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Critical Critical
    • cvs-plugin
    • None
    • Jenkins 2.303.1
      cvs-plugin 2.19
    • 2.20

      I am currently trying to work with shared librarys. In my test project I am getting a NPE when jenkins is ckecking out the library. The checkout itself works, the files are in the workspace. The NPE happens obviously during some postprocessing when jenkins wants to build a changelog for the library, indepenent if that point is checked or not in the settings. Reading the log from CVS itself seems to work according to the console output.

      Here the console and the stacktrace:

      23:30:50  Loading library MyBuild@HEAD
      23:30:50  Using locally configured password for connection to :pserver:builduser@myserver:/myproject
      23:30:50  cvs update -C -d -P -r HEAD -D 30 Sep 2021 23:30:37 +0200 MyBuild 
      23:30:50  cvs server: Updating MyBuild
      23:30:50  cvs server: Updating MyBuild/vars
      23:30:50  Using locally configured password for connection to :pserver:builduser@myserver:/myproject
      23:30:50  cvs rlog -S -d30 Sep 2021 23:13:45 +0200<30 Sep 2021 23:30:37 +0200 Libs 
      23:30:50  cvs rlog: Logging Libs
      23:30:50  cvs rlog: Logging Libs/vars
      23:30:50  ERROR: Checkout failed
      23:30:50  java.lang.NullPointerException
      23:30:50  	at java.base/java.io.FileOutputStream.<init>(Unknown Source)
      23:30:50  	at java.base/java.io.FileOutputStream.<init>(Unknown Source)
      23:30:50  	at hudson.scm.CVSChangeLogSet.toFile(CVSChangeLogSet.java:680)
      23:30:50  	at hudson.scm.AbstractCvs.postCheckout(AbstractCvs.java:828)
      23:30:50  	at hudson.scm.CVSSCM.checkout(CVSSCM.java:398)
      23:30:50  	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:129)
      23:30:50  	at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.lambda$doRetrieve$1(SCMSourceRetriever.java:190)
      23:30:50  	at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.retrySCMOperation(SCMSourceRetriever.java:140)
      23:30:50  	at org.jenkinsci.plugins.workflow.libs.SCMSourceRetriever.doRetrieve(SCMSourceRetriever.java:189)
      23:30:50  	at org.jenkinsci.plugins.workflow.libs.SCMRetriever.retrieve(SCMRetriever.java:92)
      23:30:50  	at org.jenkinsci.plugins.workflow.libs.LibraryAdder.retrieve(LibraryAdder.java:196)
      23:30:50  	at org.jenkinsci.plugins.workflow.libs.LibraryAdder.add(LibraryAdder.java:138)
      23:30:50  	at org.jenkinsci.plugins.workflow.libs.LibraryDecorator$1.call(LibraryDecorator.java:125)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
      23:30:50  	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      23:30:50  	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      23:30:50  	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
      23:30:50  	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
      23:30:50  	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
      23:30:50  	at hudson.model.ResourceController.execute(ResourceController.java:100)
      23:30:50  	at hudson.model.Executor.run(Executor.java:433)
      23:30:50  ERROR: Maximum checkout retry attempts reached, aborting
      23:30:50  org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      23:30:50  WorkflowScript: Loading libraries failed
      23:30:50  
      23:30:50  1 error
      23:30:50  
      23:30:50  	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
      23:30:50  	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
      23:30:50  	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      23:30:50  	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      23:30:50  	at groovy.lang.GroovyShell.parseClass(GroovyShell.java:688)
      23:30:50  	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:142)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:571)
      23:30:50  	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:523)
      23:30:50  	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:337)
      23:30:50  	at hudson.model.ResourceController.execute(ResourceController.java:100)
      23:30:50  	at hudson.model.Executor.run(Executor.java:433)
      23:30:50  Finished: FAILURE
      

          [JENKINS-66772] NPE when checking out a shared library from CVS

          Christoph Fetzer added a comment - - edited

          Hm, it's been a while since I programmed Java the last time... from the code I'd guess the argument changelogFile is empty (or null) and the code does not check for this but tries to open a file whith that name.

          The fix migh be just a

          if() {
          ...
          }
          

          around 12 lines of code in AbstractCvs.java.

          Anyone who can help here?

          When I got some time spare I can try to get a development environment by myself. However I still have to set up a test environment.

          Christoph Fetzer added a comment - - edited Hm, it's been a while since I programmed Java the last time... from the code I'd guess the argument changelogFile is empty (or null) and the code does not check for this but tries to open a file whith that name. The fix migh be just a if () { ... } around 12 lines of code in AbstractCvs.java. Anyone who can help here? When I got some time spare I can try to get a development environment by myself. However I still have to set up a test environment.

          The following patch seems to work for me:

          diff --git a/src/main/java/hudson/scm/AbstractCvs.java b/src/main/java/hudson/scm/AbstractCvs.java
          index c5a9d73..7249d65 100644
          --- a/src/main/java/hudson/scm/AbstractCvs.java
          +++ b/src/main/java/hudson/scm/AbstractCvs.java
          @@ -816,20 +816,23 @@
                   // build change log
                   final Run<?, ?> lastCompleteBuild = build.getPreviousBuiltBuild();
           
          -        if (lastCompleteBuild != null && !isSkipChangeLog()) {
          -            final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild);
          -            final Date checkoutDate = getCheckoutDate(build);
          +        if( null != changelogFile )
          +        {
          +            if (lastCompleteBuild != null && !isSkipChangeLog()) {
          +                final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild);
          +                final Date checkoutDate = getCheckoutDate(build);
           
          -            final List<CVSChangeLogSet.CVSChangeLog> changes = new ArrayList<CVSChangeLogSet.CVSChangeLog>();
          -            for (CvsRepository location : repositories) {
          -                changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location,
          -                        listener, build.getEnvironment(listener), workspace));
          +                final List<CVSChangeLogSet.CVSChangeLog> changes = new ArrayList<CVSChangeLogSet.CVSChangeLog>();
          +                for (CvsRepository location : repositories) {
          +                    changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location,
          +                            listener, build.getEnvironment(listener), workspace));
          +                }
          +                new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile);
          +            } else {
          +                createEmptyChangeLog(changelogFile, listener, "changelog");
                       }
          -            new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile);
          -        } else {
          -            createEmptyChangeLog(changelogFile, listener, "changelog");
                   }
          -
          +        
                   // add the current workspace state as an action
                   build.getActions().add(new CvsRevisionState(calculateWorkspaceState(workspace, repositories, flatten, envVars, listener)));
          

          Christoph Fetzer added a comment - The following patch seems to work for me: diff --git a/src/main/java/hudson/scm/AbstractCvs.java b/src/main/java/hudson/scm/AbstractCvs.java index c5a9d73..7249d65 100644 --- a/src/main/java/hudson/scm/AbstractCvs.java +++ b/src/main/java/hudson/scm/AbstractCvs.java @@ -816,20 +816,23 @@ // build change log final Run<?, ?> lastCompleteBuild = build.getPreviousBuiltBuild(); - if (lastCompleteBuild != null && !isSkipChangeLog()) { - final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild); - final Date checkoutDate = getCheckoutDate(build); + if ( null != changelogFile ) + { + if (lastCompleteBuild != null && !isSkipChangeLog()) { + final Date lastCompleteTimestamp = getCheckoutDate(lastCompleteBuild); + final Date checkoutDate = getCheckoutDate(build); - final List<CVSChangeLogSet.CVSChangeLog> changes = new ArrayList<CVSChangeLogSet.CVSChangeLog>(); - for (CvsRepository location : repositories) { - changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location, - listener, build.getEnvironment(listener), workspace)); + final List<CVSChangeLogSet.CVSChangeLog> changes = new ArrayList<CVSChangeLogSet.CVSChangeLog>(); + for (CvsRepository location : repositories) { + changes.addAll(calculateChangeLog(lastCompleteTimestamp, checkoutDate, location, + listener, build.getEnvironment(listener), workspace)); + } + new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile); + } else { + createEmptyChangeLog(changelogFile, listener, "changelog" ); } - new CVSChangeLogSet(build, getBrowser(), changes).toFile(changelogFile); - } else { - createEmptyChangeLog(changelogFile, listener, "changelog" ); } - + // add the current workspace state as an action build.getActions().add( new CvsRevisionState(calculateWorkspaceState(workspace, repositories, flatten, envVars, listener)));

          My first interaction with git: I made it to commit the code and create a pull-request. Hopefully someone with write-priviledges will merge the code and create a new release.

          Christoph Fetzer added a comment - My first interaction with git: I made it to commit the code and create a pull-request. Hopefully someone with write-priviledges will merge the code and create a new release.

          Christoph Fetzer added a comment - - edited

          solved and created a pull request. Rest of the way up to others....

          Christoph Fetzer added a comment - - edited solved and created a pull request. Rest of the way up to others....

          Basil Crow added a comment -

          Fixed in jenkinsci/cvs-plugin#57. Released in 2.20.

          Basil Crow added a comment - Fixed in jenkinsci/cvs-plugin#57 . Released in 2.20 .

            chrisfetz Christoph Fetzer
            chrisfetz Christoph Fetzer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: