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

ClassCastException when reports are created with maven-site-plugin

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • findbugs-plugin
    • None

      When enabling the Jenkins Findbugs plugin on a Maven job that uses the maven-site-plugin to generate the reports then the build fails with the root cause exception:
      java.lang.ClassCastException: org.dom4j.DocumentFactory cannot be cast to org.dom4j.DocumentFactory
      (cf. attachment for full stack-trace).

        1. test.zip
          3 kB
        2. jenkins.txt
          11 kB

          [JENKINS-15344] ClassCastException when reports are created with maven-site-plugin

          Ulli Hafner added a comment -

          Can you please add some details about your environment? Is this a slave build? Which JDK, findbugs, Jenkins, etc. is installed?

          Ulli Hafner added a comment - Can you please add some details about your environment? Is this a slave build? Which JDK, findbugs, Jenkins, etc. is installed?

          Thomas Zlika added a comment -

          I've updated the environment section of the issue. Tell me if you need other details.

          Thomas Zlika added a comment - I've updated the environment section of the issue. Tell me if you need other details.

          Ulli Hafner added a comment -

          Please add the plug-in versions of findbugs and analysis-core. And how do you start Jenkins? java -jar or Tomcat?

          Note: does this error occur when Jenkins runs using a JDK 6?

          Ulli Hafner added a comment - Please add the plug-in versions of findbugs and analysis-core. And how do you start Jenkins? java -jar or Tomcat? Note: does this error occur when Jenkins runs using a JDK 6?

          Thomas Zlika added a comment -

          analysis-core : 1.47
          findbugs : 4.44
          Starting Jenkins in standalone mode (java -jar) or deployed in a Tomcat server leads to the same problem.
          I've not tried with a JDK6 yet.

          Thomas Zlika added a comment - analysis-core : 1.47 findbugs : 4.44 Starting Jenkins in standalone mode (java -jar) or deployed in a Tomcat server leads to the same problem. I've not tried with a JDK6 yet.

          Thomas Zlika added a comment -

          Just made a test with JRE6 : same problem.

          Thomas Zlika added a comment - Just made a test with JRE6 : same problem.

          Thomas Zlika added a comment -

          According to the stack trace, it seems to be a class loading problem with dom4j.
          Using mvn dependency:tree, we can see that dom4j is used twice with 2 slightly different versions:

          • dom4j:dom4j:jar:1.6.1:compile is a transitive dependency of org.jvnet.hudson.plugins.findbugs:library:jar:2.0.1-SNAPSHOT
          • org.jvnet.hudson.dom4j:dom4j:jar:1.6.1-hudson-3:provided is a transitive dependency of org.jenkins-ci.main:jenkins-core:jar:1.409:provided

          In FindBugsParser.readXml(), where the bug occurs, you change the context class loader. And I can see in the stack trace that an async task is launched in a ThreadPoolExecutor, so the thread in the executor is certainly not using the class loader you tried to impose in FindBugsParser.readXml(), isn't it ?
          Maybe a quick-and-dirty workaround would be to explicitly exclude dom4j:dom4j:jar:1.6.1 when configuring the findbugs dependency ?

          Thomas Zlika added a comment - According to the stack trace, it seems to be a class loading problem with dom4j. Using mvn dependency:tree, we can see that dom4j is used twice with 2 slightly different versions: dom4j:dom4j:jar:1.6.1:compile is a transitive dependency of org.jvnet.hudson.plugins.findbugs:library:jar:2.0.1-SNAPSHOT org.jvnet.hudson.dom4j:dom4j:jar:1.6.1-hudson-3:provided is a transitive dependency of org.jenkins-ci.main:jenkins-core:jar:1.409:provided In FindBugsParser.readXml(), where the bug occurs, you change the context class loader. And I can see in the stack trace that an async task is launched in a ThreadPoolExecutor, so the thread in the executor is certainly not using the class loader you tried to impose in FindBugsParser.readXml(), isn't it ? Maybe a quick-and-dirty workaround would be to explicitly exclude dom4j:dom4j:jar:1.6.1 when configuring the findbugs dependency ?

          Code changed in jenkins
          User: Ulli Hafner
          Path:
          library/.classpath
          library/.project
          library/.settings/org.eclipse.core.resources.prefs
          library/.settings/org.eclipse.m2e.core.prefs
          library/pom.xml
          http://jenkins-ci.org/commit/findbugs-plugin/20fcf8f9fc4191842f63f2f3c27b1eb737fca247
          Log:
          [FIXED JENKINS-15344]: Upgrade to findbugs 2.0.1 and exclude DOM4J
          library which is already part of core.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Ulli Hafner Path: library/.classpath library/.project library/.settings/org.eclipse.core.resources.prefs library/.settings/org.eclipse.m2e.core.prefs library/pom.xml http://jenkins-ci.org/commit/findbugs-plugin/20fcf8f9fc4191842f63f2f3c27b1eb737fca247 Log: [FIXED JENKINS-15344] : Upgrade to findbugs 2.0.1 and exclude DOM4J library which is already part of core.

          Thomas Zlika added a comment -

          I tested the lattest version of Jenkins (1.484) with all the latest versions of the plugins (including analysis core 1.48 and findbugs 4.45) and unfortunately I still have the same error stack trace...

          Thomas Zlika added a comment - I tested the lattest version of Jenkins (1.484) with all the latest versions of the plugins (including analysis core 1.48 and findbugs 4.45) and unfortunately I still have the same error stack trace...

          Ulli Hafner added a comment -

          Ok, I see. I just applied your quick fix with the hope that it will work on your machine...

          Ulli Hafner added a comment - Ok, I see. I just applied your quick fix with the hope that it will work on your machine...

          Thomas Zlika added a comment -

          That was just a (bad) idea... I saw that the PMD plugin also comes with its own version of dom4j, but even if I delete it from the list of installed plugin the error still happens.
          Where you able to reproduce this problem on your machine or not ? I may try to build a small example so that you can reproduce the problem on your machine.

          Thomas Zlika added a comment - That was just a (bad) idea... I saw that the PMD plugin also comes with its own version of dom4j, but even if I delete it from the list of installed plugin the error still happens. Where you able to reproduce this problem on your machine or not ? I may try to build a small example so that you can reproduce the problem on your machine.

          Ulli Hafner added a comment -

          That would help. I can't reproduce that problem on my machine up to now...

          Ulli Hafner added a comment - That would help. I can't reproduce that problem on my machine up to now...

          Thomas Zlika added a comment -

          This very simple project (1 mock java class and 1 mock test class) can reproduce the problem.
          In fact the problem is not related to multi-module maven projects as I thought, because I can reproduce it with this mono-module project.
          The problem seems to be somehow related to the tests, because it disappears if I remove the test class.

          Thomas Zlika added a comment - This very simple project (1 mock java class and 1 mock test class) can reproduce the problem. In fact the problem is not related to multi-module maven projects as I thought, because I can reproduce it with this mono-module project. The problem seems to be somehow related to the tests, because it disappears if I remove the test class.

          Ulli Hafner added a comment -

          I can't reproduce this with your example. Is there a findbugs warning in your project? When I run it I get:

          [INFO] 
          [INFO] --- findbugs-maven-plugin:2.5.2:findbugs (default-cli) @ aggregator ---
          [INFO] Fork Value is true
          [INFO] Done FindBugs Analysis....
          mojoSucceeded org.codehaus.mojo:findbugs-maven-plugin:2.5.2(default-cli)
          [FINDBUGS] Finding all files that match the pattern findbugsXml.xml
          [FINDBUGS] Parsing 1 files in /Users/hafner/Development/jenkins/jobs/JENKINS-15344/workspace/target
          [FINDBUGS] Successfully parsed file /Users/hafner/Development/jenkins/jobs/JENKINS-15344/workspace/target/findbugsXml.xml of module aggregator with 0 warnings.
          projectSucceeded net.test:aggregator:0.1-SNAPSHOT
          sessionEnded
          
          

          There is no warning found. I'm using the goals "clean package findbugs:findbugs". What did you use?

          Ulli Hafner added a comment - I can't reproduce this with your example. Is there a findbugs warning in your project? When I run it I get: [INFO] [INFO] --- findbugs-maven-plugin:2.5.2:findbugs (default-cli) @ aggregator --- [INFO] Fork Value is true [INFO] Done FindBugs Analysis.... mojoSucceeded org.codehaus.mojo:findbugs-maven-plugin:2.5.2(default-cli) [FINDBUGS] Finding all files that match the pattern findbugsXml.xml [FINDBUGS] Parsing 1 files in /Users/hafner/Development/jenkins/jobs/JENKINS-15344/workspace/target [FINDBUGS] Successfully parsed file /Users/hafner/Development/jenkins/jobs/JENKINS-15344/workspace/target/findbugsXml.xml of module aggregator with 0 warnings. projectSucceeded net.test:aggregator:0.1-SNAPSHOT sessionEnded There is no warning found. I'm using the goals "clean package findbugs:findbugs". What did you use?

          Thomas Zlika added a comment -

          I use mvn clean site

          Thomas Zlika added a comment - I use mvn clean site

          Ulli Hafner added a comment -

          Thanks Thomas! Now I can reproduce the problem. Seems that maven-site-plugin is the cause for the exception. I need to investigate how I can update my plug-in to work with the results of this maven plugin.

          Until that is fixed, please use the goal 'findbugs:findbugs' to create the FindBugs results. Maybe it would also work if you downgrade to 3.0 maven-site-plugin, see JENKINS-14737.

          Ulli Hafner added a comment - Thanks Thomas! Now I can reproduce the problem. Seems that maven-site-plugin is the cause for the exception. I need to investigate how I can update my plug-in to work with the results of this maven plugin. Until that is fixed, please use the goal 'findbugs:findbugs' to create the FindBugs results. Maybe it would also work if you downgrade to 3.0 maven-site-plugin, see JENKINS-14737 .

          Thomas Zlika added a comment -

          "mvn clean site" works indeed with maven site plugin 3.0, but not with 3.1 or 3.2.
          I have also found another workaround: the bug vanishes if instead of doing "mvn clean site" I do "mvn clean install site" !

          Thomas Zlika added a comment - "mvn clean site" works indeed with maven site plugin 3.0, but not with 3.1 or 3.2. I have also found another workaround: the bug vanishes if instead of doing "mvn clean site" I do "mvn clean install site" !

          Falko Modler added a comment -

          Any updates? I just had to downgrade to maven-site-plugin 3.0.

          Falko Modler added a comment - Any updates? I just had to downgrade to maven-site-plugin 3.0.

          Ulli Hafner added a comment -

          @Falko: did you try the workaround noted by Thomas?

          This issue is not on my priority list So feel free to provide a patch if the workaround is not working in your environment...

          Ulli Hafner added a comment - @Falko: did you try the workaround noted by Thomas? This issue is not on my priority list So feel free to provide a patch if the workaround is not working in your environment...

          Ulli Hafner added a comment -

          I tried some ideas to get the plug-in correctly running with new site plugin, however nothing worked. I think that this actually is a problem in the class loaders of the maven plug-in in Jenkins core... Seems that they are new isolated enough.

          Ulli Hafner added a comment - I tried some ideas to get the plug-in correctly running with new site plugin, however nothing worked. I think that this actually is a problem in the class loaders of the maven plug-in in Jenkins core... Seems that they are new isolated enough.

          Andreas Horst added a comment -

          I can still confirm this on 1.574 with maven-site-plugin 3.3. Also the workaround to additionally invoke the default lifecycle (e.g. "clean package site-deploy") works. Though it would be nice to be able to just do a "clean site-deploy" in a dedicated site job.

          Andreas Horst added a comment - I can still confirm this on 1.574 with maven-site-plugin 3.3. Also the workaround to additionally invoke the default lifecycle (e.g. "clean package site-deploy") works. Though it would be nice to be able to just do a "clean site-deploy" in a dedicated site job.

          Dupliate of JENKINS-13709.

          Kohsuke Kawaguchi added a comment - Dupliate of JENKINS-13709 .

            kohsuke Kohsuke Kawaguchi
            zlika Thomas Zlika
            Votes:
            10 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved: