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

NPE during Discard Old Data

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      A user of 1.509.3 with the Metadata plugin formerly installed had some data listed in Discard Old Data screen, as expected:

      hudson.model.FreeStyleBuild
      jobname #123
      CannotResolveClassException: com.sonyericsson.hudson.plugins.metadata.model.MetadataBuildAction

      He clicked Discard and received an error:

      java.lang.NullPointerException
      	at hudson.model.AbstractItem.getRootDir(AbstractItem.java:162)
      	at hudson.model.Items.getConfigFile(Items.java:236)
      	at hudson.model.AbstractItem.getConfigFile(AbstractItem.java:461)
      	at hudson.model.AbstractItem.save(AbstractItem.java:456)
      	at hudson.model.Job.save(Job.java:152)
      	at hudson.model.AbstractProject.save(AbstractProject.java:268)
      	at hudson.diagnosis.OldDataMonitor.doDiscard(OldDataMonitor.java:275)
      

      This means that there is an AbstractProject whose parent is null. Most likely a serialized MetadataBuildAction was persisting a Run which was not identical to the build to which it had been added (this is possible due to lazy-loading), so XStream did not use a backreference but instead tried to serialize the whole build. When deserialized, the orphaned build would have had a bogus parent project.

      The solution in 1.519+ (or 1.509.3/4) is simple: use the new RunAction2. There is no alternative available for older versions of Jenkins.

        Attachments

          Issue Links

            Activity

            Hide
            jglick Jesse Glick added a comment -

            Similar to the core bug JENKINS-17125.

            Show
            jglick Jesse Glick added a comment - Similar to the core bug JENKINS-17125 .
            Hide
            esinsag Sagi Sinai-Glazer added a comment -

            Also happens with textfinder plugin on LTS 1.509.3.
            Manage Old Data gives list of entries of with:
            Type: hudson.model.FreeStyleProject
            Error: MissingFieldException: No field 'completeBuild' found in class 'hudson.model.Result', MissingFieldException: No field 'completeBuild' found in class 'hudson.model.Result', CannotResolveClassException: hudson.plugins.textfinder.TextFinderPublisher

            Trying to discard will generate NPE:
            Caused by: java.lang.NullPointerException
            at hudson.model.AbstractItem.getRootDir(AbstractItem.java:162)
            at hudson.model.Items.getConfigFile(Items.java:236)
            at hudson.model.AbstractItem.getConfigFile(AbstractItem.java:461)
            at hudson.model.AbstractItem.save(AbstractItem.java:456)
            at hudson.model.Job.save(Job.java:152)
            at hudson.model.AbstractProject.save(AbstractProject.java:268)
            at hudson.diagnosis.OldDataMonitor.doDiscard(OldDataMonitor.java:275)

            Show
            esinsag Sagi Sinai-Glazer added a comment - Also happens with textfinder plugin on LTS 1.509.3. Manage Old Data gives list of entries of with: Type: hudson.model.FreeStyleProject Error: MissingFieldException: No field 'completeBuild' found in class 'hudson.model.Result', MissingFieldException: No field 'completeBuild' found in class 'hudson.model.Result', CannotResolveClassException: hudson.plugins.textfinder.TextFinderPublisher Trying to discard will generate NPE: Caused by: java.lang.NullPointerException at hudson.model.AbstractItem.getRootDir(AbstractItem.java:162) at hudson.model.Items.getConfigFile(Items.java:236) at hudson.model.AbstractItem.getConfigFile(AbstractItem.java:461) at hudson.model.AbstractItem.save(AbstractItem.java:456) at hudson.model.Job.save(Job.java:152) at hudson.model.AbstractProject.save(AbstractProject.java:268) at hudson.diagnosis.OldDataMonitor.doDiscard(OldDataMonitor.java:275)
            Hide
            esinsag Sagi Sinai-Glazer added a comment -

            Seems like it might be a duplicate of https://issues.jenkins-ci.org/browse/JENKINS-18809

            Show
            esinsag Sagi Sinai-Glazer added a comment - Seems like it might be a duplicate of https://issues.jenkins-ci.org/browse/JENKINS-18809
            Hide
            jglick Jesse Glick added a comment -

            @esinsag no, keep JENKINS-18809 for the Claim plugin please, and if you have some issue with the Text Finder plugin file it separately and link.

            Show
            jglick Jesse Glick added a comment - @esinsag no, keep JENKINS-18809 for the Claim plugin please, and if you have some issue with the Text Finder plugin file it separately and link.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            pom.xml
            src/main/java/com/sonyericsson/hudson/plugins/metadata/cli/CliUtils.java
            src/main/java/com/sonyericsson/hudson/plugins/metadata/contributors/BuildContributorsController.java
            src/main/java/com/sonyericsson/hudson/plugins/metadata/model/MetadataBuildAction.java
            http://jenkins-ci.org/commit/metadata-plugin/0dc90f1ab6b3942b971d76d3732c45dfb0c9fa0a
            Log:
            [FIXED JENKINS-20950] Do not try to persist the build which holds this action.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: pom.xml src/main/java/com/sonyericsson/hudson/plugins/metadata/cli/CliUtils.java src/main/java/com/sonyericsson/hudson/plugins/metadata/contributors/BuildContributorsController.java src/main/java/com/sonyericsson/hudson/plugins/metadata/model/MetadataBuildAction.java http://jenkins-ci.org/commit/metadata-plugin/0dc90f1ab6b3942b971d76d3732c45dfb0c9fa0a Log: [FIXED JENKINS-20950] Do not try to persist the build which holds this action.
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Robert Sandell
            Path:
            pom.xml
            src/main/java/com/sonyericsson/hudson/plugins/metadata/cli/CliUtils.java
            src/main/java/com/sonyericsson/hudson/plugins/metadata/contributors/BuildContributorsController.java
            src/main/java/com/sonyericsson/hudson/plugins/metadata/model/MetadataBuildAction.java
            src/test/java/com/sonyericsson/hudson/plugins/metadata/cli/CliUtilsTest.java
            src/test/java/com/sonyericsson/hudson/plugins/metadata/search/MetadataViewJobFilterTest.java
            http://jenkins-ci.org/commit/metadata-plugin/60e54b20648e205cff20cb5fd154b81ea827813c
            Log:
            Merge pull request #2 from jglick/RunAction2-JENKINS-20950

            JENKINS-20950 Use RunAction2

            Compare: https://github.com/jenkinsci/metadata-plugin/compare/2842fd93fd1f...60e54b20648e

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Robert Sandell Path: pom.xml src/main/java/com/sonyericsson/hudson/plugins/metadata/cli/CliUtils.java src/main/java/com/sonyericsson/hudson/plugins/metadata/contributors/BuildContributorsController.java src/main/java/com/sonyericsson/hudson/plugins/metadata/model/MetadataBuildAction.java src/test/java/com/sonyericsson/hudson/plugins/metadata/cli/CliUtilsTest.java src/test/java/com/sonyericsson/hudson/plugins/metadata/search/MetadataViewJobFilterTest.java http://jenkins-ci.org/commit/metadata-plugin/60e54b20648e205cff20cb5fd154b81ea827813c Log: Merge pull request #2 from jglick/RunAction2- JENKINS-20950 JENKINS-20950 Use RunAction2 Compare: https://github.com/jenkinsci/metadata-plugin/compare/2842fd93fd1f...60e54b20648e
            Hide
            jglick Jesse Glick added a comment - - edited

            Not sure if the PR I submitted actually addresses the issue here. From the stack trace, it looks like the Saveable reported to have a problem was a FreeStyleProject, not a FreeStyleBuild. That would potentially implicate MetadataJobAction, yet this does not seem to save any inappropriate references; it is a bit weird that it saves a side reference to the MetadataJobProperty, but neither should save a reference to the Job which would be the dangerous thing.

            I was trying to reproduce a similar situation in a functional test to explore whether OldDataMonitor could be made to behave more gracefully in this situation:

            @Test public void savingOrphanedBuild() throws Exception {
                FreeStyleProject p = r.createFreeStyleProject("p");
                FreeStyleBuild b = p.scheduleBuild2(0).get();
                BogusAction a = new BogusAction();
                a.build = b;
                p._getRuns().purgeCache();
                b = p.getBuildByNumber(1);
                b.addAction(a);
                b.save();
                System.out.println(FileUtils.readFileToString(new File(b.getRootDir(), "build.xml")));
            }
            public static final class BogusAction extends InvisibleAction {
                Run build;
            }
            

            This produces a malformed build.xml similar to that reported for JENKINS-17125. But this is not an error condition to load, and even if it were made so (using Run.XSTREAM2.alias to deliberately break the loading of BogusAction after a reload) I would guess that OldDataMonitor.discard would be saving the Run, and doing so would not result in the NPE caused by a missing AbstractItem.parent.

            Show
            jglick Jesse Glick added a comment - - edited Not sure if the PR I submitted actually addresses the issue here. From the stack trace, it looks like the Saveable reported to have a problem was a FreeStyleProject , not a FreeStyleBuild . That would potentially implicate MetadataJobAction , yet this does not seem to save any inappropriate references; it is a bit weird that it saves a side reference to the MetadataJobProperty , but neither should save a reference to the Job which would be the dangerous thing. I was trying to reproduce a similar situation in a functional test to explore whether OldDataMonitor could be made to behave more gracefully in this situation: @Test public void savingOrphanedBuild() throws Exception { FreeStyleProject p = r.createFreeStyleProject( "p" ); FreeStyleBuild b = p.scheduleBuild2(0).get(); BogusAction a = new BogusAction(); a.build = b; p._getRuns().purgeCache(); b = p.getBuildByNumber(1); b.addAction(a); b.save(); System .out.println(FileUtils.readFileToString( new File(b.getRootDir(), "build.xml" ))); } public static final class BogusAction extends InvisibleAction { Run build; } This produces a malformed build.xml similar to that reported for JENKINS-17125 . But this is not an error condition to load, and even if it were made so (using Run.XSTREAM2.alias to deliberately break the loading of BogusAction after a reload) I would guess that OldDataMonitor.discard would be saving the Run , and doing so would not result in the NPE caused by a missing AbstractItem.parent .
            Hide
            scm_issue_link SCM/JIRA link daemon added a comment -

            Code changed in jenkins
            User: Jesse Glick
            Path:
            core/src/main/java/hudson/diagnosis/OldDataMonitor.java
            test/src/test/java/hudson/diagnosis/OldDataMonitorTest.java
            test/src/test/resources/hudson/diagnosis/OldDataMonitorTest/robustness.zip
            http://jenkins-ci.org/commit/jenkins/8508fc365ac9faa4fa6ccee116e820c0455f0988
            Log:
            JENKINS-19544 Whether or not we manage to save an object with old data, be sure to remove it from the list, and continue with other objects.
            Otherwise a bug like JENKINS-20950 can prevent anything from being saved, and holds references to all the old data.

            Show
            scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Jesse Glick Path: core/src/main/java/hudson/diagnosis/OldDataMonitor.java test/src/test/java/hudson/diagnosis/OldDataMonitorTest.java test/src/test/resources/hudson/diagnosis/OldDataMonitorTest/robustness.zip http://jenkins-ci.org/commit/jenkins/8508fc365ac9faa4fa6ccee116e820c0455f0988 Log: JENKINS-19544 Whether or not we manage to save an object with old data, be sure to remove it from the list, and continue with other objects. Otherwise a bug like JENKINS-20950 can prevent anything from being saved, and holds references to all the old data.

              People

              • Assignee:
                rsandell rsandell
                Reporter:
                jglick Jesse Glick
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: