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

Caused by: java.lang.IllegalArgumentException: Unable to inject class hudson.model.UserIdMapper

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • job-dsl-plugin
    • None

      When I execute the following test `gradle test --tests MavenJobDSLTest` using this test project - https://github.com/ch007m/jenkins-job-dsl/blob/main/README.md which contains a Java Junit test (@Rule - Jenkinsrule)

      package dev.snowdrop;
      
      import hudson.model.FreeStyleBuild;
      import hudson.model.FreeStyleProject;
      import javaposse.jobdsl.plugin.ExecuteDslScripts;
      import org.junit.Rule;
      import org.junit.Test;
      import org.jvnet.hudson.test.JenkinsRule;
      
      import java.util.ArrayList;
      
      import static org.junit.Assert.assertEquals;
      import static org.junit.Assert.assertTrue;
      
      public class MavenJobDSLTest {
          @Rule
          public JenkinsRule j = new JenkinsRule();
      
          @Test
          public void useMavenDSLGroovyFileAsJob() throws Exception {
              FreeStyleProject p = j.createFreeStyleProject();
              p.scheduleBuild2(0).get(); // run a build to create a workspace
              p.getSomeWorkspace().child("mavenProject/mavenJob.groovy").copyFrom(getClass().getResourceAsStream("/mavenJob.groovy"));
      
              ExecuteDslScripts e = new ExecuteDslScripts();
              e.setTargets("mavenProject/mavenJob.groovy");
              p.getBuildersList().add(e);
      
              // Assert if build succeeded, if the Script executed includes the echo message
              FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0).get());
              b.keepLog();
      
              assertEquals(2, b.number);
              assertEquals("#2",b.getDisplayName());
              assertEquals("SUCCESS",b.getResult().toString());
      
              // Check if the FreeStyleProject build reported that it generated the job: say-hello-world
              ArrayList LogResult = (ArrayList) b.getLog(100);
              //LogResult.forEach((s) -> System.out.println(s));
              assertTrue(b.getLog(100).stream().anyMatch(str -> str.contains("GeneratedJob{name='say-hello-world'}")));
      
              // Get the FreeStyleProject containing the Job DSL steps to be executed - Say Hello World
              FreeStyleProject freeStyleProjectGeneratedJob = (FreeStyleProject) j.jenkins.getItem("say-hello-world");
              FreeStyleBuild b2 =  freeStyleProjectGeneratedJob.scheduleBuild2(0).get();
      
              assertEquals(1, b2.number);
              assertEquals("#1",b2.getDisplayName());
              assertEquals("SUCCESS",b2.getResult().toString());
      
              // Check if the FreeStyleProject build reported that it generated the job: say-hello-world
              assertTrue(b2.getLog(100).stream().anyMatch(str -> str.contains("Say Hello World !")));
      
              /* Added for debugging and logging purposes ;)
                 LogResult = (ArrayList) b2.getLog(100);
                 LogResult.forEach((s) -> System.out.println(s));
                 System.out.println("//");
               */
          }
      }
      

      and mavenJob.groovy

      // See: https://www.happycoders.eu/devops/jenkins-tutorial-create-jobs-with-job-dsl/
      mavenJob('mvn-spring-boot-rest-http') {
          description 'A Maven Job compiling the project Spring Boot Rest HTTP Example'
      
          parameters {
              gitParameter {
                  name 'SELECTED_TAG'
                  description 'The Git tag to checkout'
                  type 'PT_TAG'
                  defaultValue '2.3.4-2'
                  branch ''
                  branchFilter 'origin/(.*)'
                  quickFilterEnabled false
                  selectedValue 'DEFAULT'
                  sortMode 'DESCENDING_SMART'
                  tagFilter '*'
                  useRepository '.*rest-http-example.git'
                  listSize '10'
              }
          }
      
          scm {
              git {
                  remote {
                      url 'https://github.com/snowdrop/rest-http-example.git'
                      // branch('$SELECTED_TAG')
                      branch('2.3.4-2')
                  }
              }
          }
          rootPOM 'pom.xml'
          goals 'clean install'
      }

      and where the dependencies have been defined using the groovy scripts as defined within the README of the project

      Jenkins.instance.pluginManager.plugins
          .findAll { !(it.shortName in ['job-dsl', 'structs']) }
          .collect { "testPlugins '${it.manifest.mainAttributes.getValue("Group-Id")}:${it.shortName}:${it.version}'" }
          .sort()
          .each { println it }
      
      and testCompile dependencies
      Jenkins.instance.pluginManager.plugins
          .findAll { !(it.shortName in ['job-dsl', 'structs']) }
          .collect { "testCompile '${it.manifest.mainAttributes.getValue("Group-Id")}:${it.shortName}:${it.version}@jar'" }
          .sort()
          .each { println it }

       

      then we got a testing error

      gradle test --tests MavenJobDSLTest                                                         > Task :test
      WARNING: An illegal reflective access operation has occurred
      WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/Users/cmoullia/.gradle/caches/modules-2/files-2.1/org.jvnet.hudson/xstream/1.4.7-jenkins-1/161ed1603117c2d37b864f81a0d62f36cf7e958a/xstream-1.4.7-jenkins-1.jar) to field java.util.TreeMap.comparator
      WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
      WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
      WARNING: All illegal access operations will be denied in a future releasedev.snowdrop.MavenJobDSLTest > useMavenDSLGroovyFileAsJob FAILED
          org.jvnet.hudson.reactor.ReactorException at Reactor.java:282
              Caused by: java.lang.Error at TaskMethodFinder.java:110
                  Caused by: java.lang.reflect.InvocationTargetException at NativeMethodAccessorImpl.java:-2
                      Caused by: java.lang.IllegalStateException at ExtensionList.java:4511 test completed, 1 failed
      
      

      The report of the test reports the following error

      org.jvnet.hudson.reactor.ReactorException: java.lang.Error: java.lang.reflect.InvocationTargetException
      	at org.jvnet.hudson.reactor.Reactor.execute(Reactor.java:282)
      	at jenkins.InitReactorRunner.run(InitReactorRunner.java:50)
      	at jenkins.model.Jenkins.executeReactor(Jenkins.java:1162)
      	at jenkins.model.Jenkins.<init>(Jenkins.java:962)
      	at hudson.model.Hudson.<init>(Hudson.java:85)
      	at org.jvnet.hudson.test.JenkinsRule.newHudson(JenkinsRule.java:688)
      	at org.jvnet.hudson.test.JenkinsRule.before(JenkinsRule.java:404)
      	at org.jvnet.hudson.test.JenkinsRule$1.evaluate(JenkinsRule.java:595)
      	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:288)
      	at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:282)
      	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      	at java.base/java.lang.Thread.run(Thread.java:834)
      Caused by: java.lang.Error: java.lang.reflect.InvocationTargetException
      	at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:110)
      	at hudson.init.TaskMethodFinder$TaskImpl.run(TaskMethodFinder.java:175)
      	at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:296)
      	at jenkins.model.Jenkins$5.runTask(Jenkins.java:1129)
      	at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:214)
      	at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:117)
      	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
      	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
      	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
      	... 1 more
      Caused by: java.lang.reflect.InvocationTargetException
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
      	at hudson.init.TaskMethodFinder.invoke(TaskMethodFinder.java:104)
      	... 9 more
      Caused by: java.lang.IllegalStateException: Expected 1 instance of hudson.PluginManager$PluginUpdateMonitor but got 0
      	at hudson.ExtensionList.lookupSingleton(ExtensionList.java:451)
      	at hudson.PluginManager$PluginUpdateMonitor.getInstance(PluginManager.java:2310)
      	at hudson.maven.PluginImpl.init(PluginImpl.java:58)
      	... 14 more
      

      and stderror

      see gist: https://gist.github.com/cmoulliard/1a9d807dec9b068ab6889ec8afa48d2e

          [JENKINS-64463] Caused by: java.lang.IllegalArgumentException: Unable to inject class hudson.model.UserIdMapper

          Gavin Mogan added a comment -

          As a non maintainer, The ticket is great and detailed, but you really need to provide your environment. (JDK version, Plugins version, Jenkins version, etc)

          "An illegal reflective access operation has occurred" code that isn't updated fully to jdk11 (well 9+), so try again with jdk 8 runtime?

          Gavin Mogan added a comment - As a non maintainer, The ticket is great and detailed, but you really need to provide your environment. (JDK version, Plugins version, Jenkins version, etc) "An illegal reflective access operation has occurred" code that isn't updated fully to jdk11 (well 9+), so try again with jdk 8 runtime?

          I updated the section environment of this ticket but here is the information

          Charles Moulliard added a comment - I updated the section environment of this ticket but here is the information macos JDK: openjdk 11.0.2 2019-01-15 Jenkins versions tested: 2.235.5 and 2.271 Plugins list as calculated using groovy script:  https://github.com/ch007m/jenkins-job-dsl/blob/main/build.gradle#L243-L381  

          Charles Moulliard added a comment - - edited

          I did a new test using jdk8 and error is still there

           

          gradle -version------------------------------------------------------------
          Gradle 6.7.1
          ------------------------------------------------------------Build time:   2020-11-16 17:09:24 UTC
          Revision:     2972ff02f3210d2ceed2f1ea880f026acfbab5c0Kotlin:       1.3.72
          Groovy:       2.5.12
          Ant:          Apache Ant(TM) version 1.10.8 compiled on May 10 2020
          JVM:          1.8.0_275 (AdoptOpenJDK 25.275-b01)
          OS:           Mac OS X 10.15.7 x86_64
          
          

          Error reported by stderr: https://gist.github.com/cmoulliard/df92c652096344d6843c0587bb9950be#file-gistfile1-txt-L3735-L3756

           

          Could the problem  be due to the following guice errors: https://gist.github.com/cmoulliard/df92c652096344d6843c0587bb9950be#file-gistfile1-txt-L3629-L3666 ?

          Charles Moulliard added a comment - - edited I did a new test using jdk8 and error is still there   gradle -version------------------------------------------------------------ Gradle 6.7.1 ------------------------------------------------------------Build time: 2020-11-16 17:09:24 UTC Revision: 2972ff02f3210d2ceed2f1ea880f026acfbab5c0Kotlin: 1.3.72 Groovy: 2.5.12 Ant: Apache Ant(TM) version 1.10.8 compiled on May 10 2020 JVM: 1.8.0_275 (AdoptOpenJDK 25.275-b01) OS: Mac OS X 10.15.7 x86_64 Error reported by stderr:  https://gist.github.com/cmoulliard/df92c652096344d6843c0587bb9950be#file-gistfile1-txt-L3735-L3756   Could the problem  be due to the following guice errors: https://gist.github.com/cmoulliard/df92c652096344d6843c0587bb9950be#file-gistfile1-txt-L3629-L3666  ?

            jamietanna Jamie Tanna
            cmoulliard Charles Moulliard
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: