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

java.lang.IllegalAccessError: class com.google.googlejavaformat.java.RemoveUnusedImports when building core with Java 17

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • core
    • None
    • 2.357

      Steps to reproduce

      Check out Jenkins core, set your compiler to Java 17, then run mvn clean verify -DskipTests.

      Expected results

      (Note: These are the actual results when running on Java 8 or Java 11.)

      The code compiles successfully.

      Actual results

      Compilation fails with

      Caused by: java.lang.IllegalAccessError: class com.google.googlejavaformat.java.RemoveUnusedImports (in unnamed module @0x210d7d3f) cannot access class com.sun.tools.javac.util.Context (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.util to unnamed module @0x210d7d3f
          at com.google.googlejavaformat.java.RemoveUnusedImports.removeUnusedImports (RemoveUnusedImports.java:218)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
          at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke (Method.java:568)
          at com.diffplug.spotless.java.GoogleJavaFormatStep$State.lambda$constructRemoveUnusedFunction$4 (GoogleJavaFormatStep.java:210)
          at com.diffplug.spotless.java.GoogleJavaFormatStep$State.lambda$createRemoveUnusedImportsOnly$2 (GoogleJavaFormatStep.java:187)
          at com.diffplug.spotless.FormatterFunc.apply (FormatterFunc.java:32)
          at com.diffplug.spotless.FormatterStepImpl$Standard.format (FormatterStepImpl.java:78)
          at com.diffplug.spotless.FormatterStep$Strict.format (FormatterStep.java:88)
          at com.diffplug.spotless.Formatter.compute (Formatter.java:230)
          at com.diffplug.spotless.PaddedCell.calculateDirtyState (PaddedCell.java:203)
          at com.diffplug.spotless.PaddedCell.calculateDirtyState (PaddedCell.java:190)
          at com.diffplug.spotless.maven.SpotlessCheckMojo.process (SpotlessCheckMojo.java:51)
          at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute (AbstractSpotlessMojo.java:195)
          at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
          at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
          at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
          at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
          at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
          at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
          at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
          at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
          at org.apache.maven.cli.MavenCli.execute (MavenCli.java:972)
          at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
          at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
          at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
          at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke (Method.java:568)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
          at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
          at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
          at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
      

          [JENKINS-68015] java.lang.IllegalAccessError: class com.google.googlejavaformat.java.RemoveUnusedImports when building core with Java 17

          Basil Crow added a comment -

          A workaround is documented here:

            Note on using Google Java Format with Java 16+

          Using Java 16+ with Google Java Format 1.10.0 requires additional flags to the running JDK. These Flags can be provided using MAVEN_OPTS environment variable or using the ./mvn/jvm.config file (See documentation).

          For example the following file under .mvn/jvm.config will run maven with the required flags: --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

          This is a workaround to a pending issue.

          Applying this workaround gets the code to compile in Java 17 and Java 11, but it breaks compilation on Java 8:

          $ cat .mvn/jvm.config
          -Xmx800m --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
          $ mvn clean verify -DskipTests
          Unrecognized option: --add-exports
          Error: Could not create the Java Virtual Machine.
          Error: A fatal exception has occurred. Program will exit.
          

          Basil Crow added a comment - A workaround is documented here :   Note on using Google Java Format with Java 16+ Using Java 16+ with Google Java Format 1.10.0 requires additional flags to the running JDK. These Flags can be provided using MAVEN_OPTS environment variable or using the ./mvn/jvm.config file (See documentation ). For example the following file under .mvn/jvm.config will run maven with the required flags: --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED This is a workaround to a pending issue . Applying this workaround gets the code to compile in Java 17 and Java 11, but it breaks compilation on Java 8: $ cat .mvn/jvm.config -Xmx800m --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED $ mvn clean verify -DskipTests Unrecognized option: --add-exports Error: Could not create the Java Virtual Machine. Error: A fatal exception has occurred. Program will exit.

            basil Basil Crow
            basil Basil Crow
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: