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

Null pointer exception in h.p.emailext.plugins.ContentBuilder

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: Major Major
    • email-ext-plugin
    • None

      After spinning up a new master, emails sent by email-ext were not getting their variables expanded. In the Jenkins server log we were seeing an NPE from h.p.emailext.plugins.ContentBuilder every time email-ext attempted to send an email:

      ERROR h.p.emailext.plugins.ContentBuilder - null
      java.lang.NullPointerException: null

      After some debugging we found that privateMacros had a null in it. it gets populated here:

      https://github.com/jenkinsci/email-ext-plugin/blob/email-ext-2.40.2/src/main/java/hudson/plugins/emailext/plugins/ContentBuilder.java#L91-L105

      (We are using version 2.40.2 but the code is the same in master.)

      Using the script console, when we dumped the value of hudson.plugins.emailext.plugins.ContentBuilder.privateMacros we could see the null, but also I noticed that every possible macro is there 5x. On our other hosts there is only one reference to each. This is the output I got:

      Result: [hudson.plugins.emailext.plugins.content.WorkspaceFileContent@2f3e714d,
      hudson.plugins.emailext.plugins.content.WorkspaceFileContent@35a87fd5,
      hudson.plugins.emailext.plugins.content.WorkspaceFileContent@5915b554,
      hudson.plugins.emailext.plugins.content.WorkspaceFileContent@327b4d1,
      hudson.plugins.emailext.plugins.content.WorkspaceFileContent@5f4f09e1,
      hudson.plugins.emailext.plugins.content.BuildLogRegexContent@296f830a,
      hudson.plugins.emailext.plugins.content.BuildLogRegexContent@5da42c66,
      hudson.plugins.emailext.plugins.content.BuildLogRegexContent@639b9a3f,
      hudson.plugins.emailext.plugins.content.BuildLogRegexContent@44bc87ac,
      hudson.plugins.emailext.plugins.content.ProjectURLContent@119e3be2,
      hudson.plugins.emailext.plugins.content.ProjectURLContent@6d25f2ab,
      hudson.plugins.emailext.plugins.content.ProjectURLContent@5250c752,
      hudson.plugins.emailext.plugins.content.BuildLogRegexContent@72f1bb53,
      hudson.plugins.emailext.plugins.content.BuildLogContent@12d0cfc4,
      hudson.plugins.emailext.plugins.content.BuildLogContent@50a2c79f,
      hudson.plugins.emailext.plugins.content.BuildLogContent@49cf08e,
      hudson.plugins.emailext.plugins.content.ProjectURLContent@7bc8f86d,
      hudson.plugins.emailext.plugins.content.BuildIdContent@6f72b63f,
      hudson.plugins.emailext.plugins.content.BuildIdContent@29aa1a71,
      hudson.plugins.emailext.plugins.content.BuildIdContent@4a51874a,
      hudson.plugins.emailext.plugins.content.ProjectURLContent@766605fd,
      hudson.plugins.emailext.plugins.content.SVNRevisionContent@c5f9640,
      hudson.plugins.emailext.plugins.content.SVNRevisionContent@755f7c28,
      hudson.plugins.emailext.plugins.content.SVNRevisionContent@3372ce1e,
      hudson.plugins.emailext.plugins.content.BuildLogContent@75fd6c60,
      hudson.plugins.emailext.plugins.content.BuildNumberContent@5e00909,
      hudson.plugins.emailext.plugins.content.BuildNumberContent@bd08ba1,
      hudson.plugins.emailext.plugins.content.BuildNumberContent@2e77a6fb,
      hudson.plugins.emailext.plugins.content.BuildLogContent@30f75139,
      hudson.plugins.emailext.plugins.content.JobDescriptionContent@355abe6f,
      hudson.plugins.emailext.plugins.content.JobDescriptionContent@3ad8b6e6,
      hudson.plugins.emailext.plugins.content.JobDescriptionContent@290b8f38,
      hudson.plugins.emailext.plugins.content.BuildIdContent@23ff7db9,
      null,
      hudson.plugins.emailext.plugins.content.TemplateContent@43b6166f,
      hudson.plugins.emailext.plugins.content.TemplateContent@3c26e779,
      hudson.plugins.emailext.plugins.content.BuildIdContent@49a1dd8a,
      hudson.plugins.emailext.plugins.content.BuildURLContent@116b63b2,
      hudson.plugins.emailext.plugins.content.BuildURLContent@621d0a9e,
      hudson.plugins.emailext.plugins.content.BuildURLContent@690b348b,
      hudson.plugins.emailext.plugins.content.SVNRevisionContent@2e81f9ad,
      hudson.plugins.emailext.plugins.content.BuildNumberContent@64bd693c,
      hudson.plugins.emailext.plugins.content.JobDescriptionContent@6e7ec6cf,
      hudson.plugins.emailext.plugins.content.TemplateContent@5ee108e7,
      hudson.plugins.emailext.plugins.content.BuildURLContent@7f0cde07,
      hudson.plugins.emailext.plugins.content.SVNRevisionContent@70f7bc53,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastUnstableBuildContent@6827543c,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastUnstableBuildContent@3ed7cfef,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastUnstableBuildContent@27b2d2d4,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastUnstableBuildContent@6aeaf755,
      hudson.plugins.emailext.plugins.content.BuildNumberContent@383ed880,
      hudson.plugins.emailext.plugins.content.BuildLogExcerptContent@3816d0df,
      hudson.plugins.emailext.plugins.content.BuildLogExcerptContent@903817b,
      hudson.plugins.emailext.plugins.content.BuildLogExcerptContent@34ee8f51,
      hudson.plugins.emailext.plugins.content.BuildLogExcerptContent@7a5abb94,
      hudson.plugins.emailext.plugins.content.CauseContent@74441c28,
      hudson.plugins.emailext.plugins.content.CauseContent@61594382,
      hudson.plugins.emailext.plugins.content.CauseContent@210ddcff,
      hudson.plugins.emailext.plugins.content.JobDescriptionContent@ea45551,
      hudson.plugins.emailext.plugins.content.JenkinsURLContent@5a55bdf1,
      hudson.plugins.emailext.plugins.content.JenkinsURLContent@71bbb06a,
      hudson.plugins.emailext.plugins.content.JenkinsURLContent@3e9e7086,
      hudson.plugins.emailext.plugins.content.CauseContent@123cb4d9,
      hudson.plugins.emailext.plugins.content.ScriptContent@65f1395a,
      hudson.plugins.emailext.plugins.content.ScriptContent@4965ed6e,
      hudson.plugins.emailext.plugins.content.ScriptContent@432ae84,
      hudson.plugins.emailext.plugins.content.TemplateContent@735f58a7,
      hudson.plugins.emailext.plugins.content.JellyScriptContent@1f88847f,
      hudson.plugins.emailext.plugins.content.JellyScriptContent@7960047d,
      hudson.plugins.emailext.plugins.content.JellyScriptContent@6837c35b,
      hudson.plugins.emailext.plugins.content.JenkinsURLContent@6124349a,
      hudson.plugins.emailext.plugins.content.BuildStatusContent@3a54ffbd,
      hudson.plugins.emailext.plugins.content.BuildStatusContent@436e5766,
      hudson.plugins.emailext.plugins.content.BuildStatusContent@1595694b,
      hudson.plugins.emailext.plugins.content.BuildURLContent@55d51f87,
      hudson.plugins.emailext.plugins.content.BuildLogMultilineRegexContent@48e1ab97,
      hudson.plugins.emailext.plugins.content.BuildLogMultilineRegexContent@7905008a,
      hudson.plugins.emailext.plugins.content.BuildLogMultilineRegexContent@47e4f1d0,
      hudson.plugins.emailext.plugins.content.ScriptContent@3a30e78c,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastSuccessfulBuildContent@7f484e4e,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastSuccessfulBuildContent@2e98007d,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastSuccessfulBuildContent@4e121e0f,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastUnstableBuildContent@73a38cc6,
      hudson.plugins.emailext.plugins.content.FailedTestsContent@4e2486c2,
      hudson.plugins.emailext.plugins.content.FailedTestsContent@2051ec93,
      hudson.plugins.emailext.plugins.content.FailedTestsContent@7eed6cf0,
      hudson.plugins.emailext.plugins.content.JellyScriptContent@11471a57,
      hudson.plugins.emailext.plugins.content.TestCountsContent@7bbf9c2b,
      hudson.plugins.emailext.plugins.content.TestCountsContent@5425c2bb,
      hudson.plugins.emailext.plugins.content.TestCountsContent@41baae23,
      hudson.plugins.emailext.plugins.content.BuildLogExcerptContent@680691e1,
      hudson.plugins.emailext.plugins.content.ProjectNameContent@6f5f060e,
      hudson.plugins.emailext.plugins.content.ProjectNameContent@15152144,
      hudson.plugins.emailext.plugins.content.ProjectNameContent@14a5e73,
      hudson.plugins.emailext.plugins.content.BuildStatusContent@5d9f5e22,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastBuildContent@4a675ce9,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastBuildContent@76c44be0,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastBuildContent@25ae2a8d,
      hudson.plugins.emailext.plugins.content.CauseContent@2e70e54,
      hudson.plugins.emailext.plugins.content.BuildLogMultilineRegexContent@72179af5,
      hudson.plugins.emailext.plugins.content.JenkinsURLContent@2658441c,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastSuccessfulBuildContent@72f6e818,
      hudson.plugins.emailext.plugins.content.ScriptContent@4859cdbc,
      hudson.plugins.emailext.plugins.content.FailedTestsContent@6572670,
      hudson.plugins.emailext.plugins.content.TestCountsContent@624bfa02,
      hudson.plugins.emailext.plugins.content.ProjectNameContent@27b8687b,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastBuildContent@218a751d,
      hudson.plugins.emailext.plugins.content.JellyScriptContent@1e51b3fa,
      hudson.plugins.emailext.plugins.content.BuildStatusContent@23f7d1d8,
      hudson.plugins.emailext.plugins.content.BuildLogMultilineRegexContent@47e88e6d,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastSuccessfulBuildContent@35b83910,
      hudson.plugins.emailext.plugins.content.FailedTestsContent@2665923e,
      hudson.plugins.emailext.plugins.content.TestCountsContent@3b01fe3b,
      hudson.plugins.emailext.plugins.content.ProjectNameContent@389984d0,
      hudson.plugins.emailext.plugins.content.ChangesSinceLastBuildContent@4c1d4a6a]

      We were able to work around the NPE by running hudson.plugins.emailext.plugins.ContentBuilder.privateMacros.remove(null) in the script console to remove the null value. But this duplication of references still seems bad. 

      danielbeck felt that this design of using privateMacros as a sort of cache of possible macros was prone to issues like this and might benefit from a redesign.

          [JENKINS-47461] Null pointer exception in h.p.emailext.plugins.ContentBuilder

          slide_o_mix after a little investigation I see there is a TokenMacro.all() should I just replace all calls to getPrivateMacros with it?

          David van Laatum added a comment - slide_o_mix after a little investigation I see there is a TokenMacro.all() should I just replace all calls to getPrivateMacros with it?

          Alex Earl added a comment -

          The private macros in email-ext were ones that should not be exported outside of email-ext. They aren't useful as token macros to anything else. So, no, calling TokenMacro.all() won't do the same thing.

          Alex Earl added a comment - The private macros in email-ext were ones that should not be exported outside of email-ext. They aren't useful as token macros to anything else. So, no, calling TokenMacro.all() won't do the same thing.

          Daniel Beck added a comment -

          Still curious why there's multiple instances of each macro here.

          My best guess as to what happened on Owen's instance is that one of the macros was unloadable so the instance() call returned null. Not adding nulls to the list should be a straightforward robustness improvement.

          Daniel Beck added a comment - Still curious why there's multiple instances of each macro here. My best guess as to what happened on Owen's instance is that one of the macros was unloadable so the instance() call returned null. Not adding nulls to the list should be a straightforward robustness improvement.

          I question where items like 

          hudson.plugins.emailext.plugins.content.JenkinsURLContent@6124349a, 

          come from since that doesn't exist in the plugin nor in token macro plugin... you didn't have an old version installed at some point and its left class files hanging around that the index lookup somehow found? Im wondering if there really is multiple versions of these classes hanging around somehow

          David van Laatum added a comment - I question where items like  hudson.plugins.emailext.plugins.content.JenkinsURLContent@6124349a,  come from since that doesn't exist in the plugin nor in token macro plugin... you didn't have an old version installed at some point and its left class files hanging around that the index lookup somehow found? Im wondering if there really is multiple versions of these classes hanging around somehow

          Owen Mehegan added a comment -

          We are using old versions of both plugins. 1.10 of token-macro and 2.40.2 of email-ext. So it's possible that this item existed in these older versions. I'll take, "You should upgrade," as a remediation item, but this was a new install of Jenkins on new hardware, so it isn't like it had been running for a long time or anything.

          Owen Mehegan added a comment - We are using old versions of both plugins. 1.10 of token-macro and 2.40.2 of email-ext. So it's possible that this item existed in these older versions. I'll take, "You should upgrade," as a remediation item, but this was a new install of Jenkins on new hardware, so it isn't like it had been running for a long time or anything.

          Alex Earl added a comment -

          Is this still an issue?

          Alex Earl added a comment - Is this still an issue?

          Owen Mehegan added a comment -

          I no longer work at the company where I saw this issue.

          Owen Mehegan added a comment - I no longer work at the company where I saw this issue.

            slide_o_mix Alex Earl
            owenmehegan Owen Mehegan
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: