Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 18 compatibility #423

Closed
ginkel opened this issue Apr 21, 2022 · 16 comments
Closed

Java 18 compatibility #423

ginkel opened this issue Apr 21, 2022 · 16 comments

Comments

@ginkel
Copy link

ginkel commented Apr 21, 2022

Hi there,

running the spotbugs-maven-plugin (v4.6.0.0) on Maven 3.8.4 under Java 18 ends up with the following exception:

$ mvn spotbugs:spotbugs
[...]

[ERROR] Failed to execute goal com.github.spotbugs:spotbugs-maven-plugin:4.6.0.0:spotbugs (spotbugs) on project foo: Execution spotbugs of goal com.github.spotbugs:spotbugs-maven-plugin:4.6.0.0:spotbugs failed: java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.spotbugs:spotbugs-maven-plugin:4.6.0.0:spotbugs (spotbugs) on project foo: Execution spotbugs of goal com.github.spotbugs:spotbugs-maven-plugin:4.6.0.0:spotbugs failed: java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
    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.MojoExecutor.executeForkedExecutions (MojoExecutor.java:355)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:200)
    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.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    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)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution spotbugs of goal com.github.spotbugs:spotbugs-maven-plugin:4.6.0.0:spotbugs failed: java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
    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.MojoExecutor.executeForkedExecutions (MojoExecutor.java:355)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:200)
    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.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    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)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)
Caused by: org.apache.tools.ant.BuildException: java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
    at org.apache.tools.ant.taskdefs.ExecuteJava.execute (ExecuteJava.java:194)
    at org.apache.tools.ant.taskdefs.Java.run (Java.java:891)
    at org.apache.tools.ant.taskdefs.Java.executeJava (Java.java:231)
    at org.apache.tools.ant.taskdefs.Java.executeJava (Java.java:135)
    at org.apache.tools.ant.taskdefs.Java.execute (Java.java:108)
    at org.apache.tools.ant.UnknownElement.execute (UnknownElement.java:299)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute (DispatchUtils.java:99)
    at groovy.ant.AntBuilder.performTask (AntBuilder.java:347)
    at groovy.ant.AntBuilder.nodeCompleted (AntBuilder.java:286)
    at groovy.util.BuilderSupport.doInvokeMethod (BuilderSupport.java:161)
    at groovy.ant.AntBuilder.doInvokeMethod (AntBuilder.java:219)
    at groovy.util.BuilderSupport.invokeMethod (BuilderSupport.java:75)
    at org.codehaus.groovy.vmplugin.v8.IndyGuardsFiltersAndSignatures.invokeGroovyObjectInvoker (IndyGuardsFiltersAndSignatures.java:160)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache (IndyInterface.java:318)
    at org.codehaus.mojo.spotbugs.SpotBugsMojo.executeSpotbugs (SpotBugsMojo.groovy:1082)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache (IndyInterface.java:318)
    at org.codehaus.mojo.spotbugs.SpotBugsMojo.canGenerateReport (SpotBugsMojo.groovy:582)
    at org.codehaus.groovy.vmplugin.v8.IndyInterface.fromCache (IndyInterface.java:318)
    at org.codehaus.mojo.spotbugs.SpotBugsMojo.execute (SpotBugsMojo.groovy:718)
    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.MojoExecutor.executeForkedExecutions (MojoExecutor.java:355)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:200)
    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.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    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)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    at java.lang.reflect.Method.invoke (Method.java:577)
    at org.apache.maven.wrapper.BootstrapMainStarter.start (BootstrapMainStarter.java:39)
    at org.apache.maven.wrapper.WrapperExecutor.execute (WrapperExecutor.java:122)
    at org.apache.maven.wrapper.MavenWrapperMain.main (MavenWrapperMain.java:61)
Caused by: java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
    at java.lang.System.setSecurityManager (System.java:416)
    at org.apache.tools.ant.types.Permissions.setSecurityManager (Permissions.java:103)
    at org.apache.tools.ant.taskdefs.ExecuteJava.run (ExecuteJava.java:216)
    at java.lang.Thread.run (Thread.java:833)

Any ideas?

@hazendaz
Copy link
Member

See https://openjdk.java.net/jeps/411

Try

-Djava.security.manager=allow

To continue to allow it, its off by default with 18.

@ginkel
Copy link
Author

ginkel commented Apr 21, 2022

Sure,

MAVEN_OPTS="-Djava.security.manager=allow" mvn spotbugs:spotbugs

works as a workaround, but IMHO it would be desirable if the plugin worked out-of-the-box, wouldn't it?

@hazendaz
Copy link
Member

plugin is written in groovy, its still using it based off that stack (the groovy ant code). I checked groovy github and last they have on it is some prep work preparing to deprecate it so it really would hinge on them.

@hazendaz
Copy link
Member

Closing issue, updated readme to note considerations such as this. Groovy has no fix yet. They reverted the code they were applying and noted it will be sometime in the future done some other way. Unfortunately this plugin is limited by their speed at getting compliant with java and there are work arounds which are now directly noted with link to details in groovy.

@ginkel
Copy link
Author

ginkel commented Apr 23, 2022

Thanks for the update!

@jrivard
Copy link

jrivard commented Dec 21, 2022

Is there a groovy issue open for this? I wasn't able to find one.

@Yaytay
Copy link

Yaytay commented Apr 11, 2023

I've just been annoyed by this yet again and thought it would be useful to put everything I could find here, because I think this issue is lacking in good information.
This is all my understanding, and if it's wrong I'd be grateful if one of the maintainers of this repo could correct it:

The error generated by spotbugs-maven-plugin isn't caused by spotbugs, it's caused by groovy using the security manager to prevent System.exit from working.
The note regarding this problem for this plugin can be found here: https://github.com/spotbugs/spotbugs-maven-plugin#groovy
The note regarding this problem from the groovy team can be found here: https://groovy-lang.org/releasenotes/groovy-4.0.html#Groovy4.0releasenotes-4.0.2
The JEP for removing the security manager is https://openjdk.org/jeps/411
Finally, the 5 year old bug in the JDK that groozy are waiting for it here: https://bugs.openjdk.org/browse/JDK-8199704

I don't think that issue is ever going to be fixed, and the groovy team don't look like they are very keen on keeping up with JDK developments. :(

My preferred workaround is to make the spotbugs-maven-plugin fork and then specify the system property for it (preferred because this way limits the workaround to only affecting spotbugs-maven-plugin):

      <plugin>
        <groupId>com.github.spotbugs</groupId>
        <artifactId>spotbugs-maven-plugin</artifactId>
        <version>4.7.3.4</version>
        <configuration>
          <fork>true</fork>
          <effort>Max</effort>
          <xmlOutput>true</xmlOutput>
          <excludeFilterFile>${basedir}/findbugsFilterFile.xml</excludeFilterFile>
          <jvmArgs>-Djava.security.manager=allow</jvmArgs>
          <plugins>
            <plugin>
              <groupId>com.h3xstream.findsecbugs</groupId>
              <artifactId>findsecbugs-plugin</artifactId>
              <version>1.12.0</version>
            </plugin>
          </plugins>
        </configuration>
        <executions>
          <execution>
            <phase>verify</phase>
            <goals>
              <goal>check</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

@hazendaz
Copy link
Member

hazendaz commented Apr 11, 2023 via email

@jglick
Copy link

jglick commented Apr 11, 2023

The issue is not with Groovy per se, it is with Ant, which this mojo explicitly uses to run SpotBugs for some reason (merely using a Groovy utility to prepare the Ant usage). I filed apache/ant#200 to deal with this upstream, though it would be better to drop the Ant dependency and either fork via ProcessBuilder or directly run the SpotBugs entry point class.

As far as I can tell the workaround is just to configure the mojo to fork—there is no need to set any special JVM arguments, since the System.setSecurityManager call is only used inside the Maven JVM when fork is false.

@JoostK
Copy link

JoostK commented Apr 14, 2023

The issue is not with Groovy per se, it is with Ant, which this mojo explicitly uses to run SpotBugs for some reason (merely using a Groovy utility to prepare the Ant usage). I filed apache/ant#200 to deal with this upstream, though it would be better to drop the Ant dependency and either fork via ProcessBuilder or directly run the SpotBugs entry point class.

As far as I can tell the workaround is just to configure the mojo to fork—there is no need to set any special JVM arguments, since the System.setSecurityManager call is only used inside the Maven JVM when fork is false.

Thanks for this insight, although I am seeing the opposite: fork needs to be set to false to avoid the warnings.

@Yaytay
Copy link

Yaytay commented Apr 14, 2023

As far as I can tell the workaround is just to configure the mojo to fork—there is no need to set any special JVM arguments, since the System.setSecurityManager call is only used inside the Maven JVM when fork is false.

I can confirm that this (<fork>true</fork>, without needing the jvmArgs) does work for me.

@jglick
Copy link

jglick commented Aug 11, 2023

Should be reopened once apache/ant@689b6ea is released.

@hazendaz
Copy link
Member

@jglick I know you mentioned this project does this strangely using ant. If you know groovy well enough and think you could figure out how to get it off that, it would be a great help. I didn't write the original code but am basically by myself with this. I'd love to dump ant and also not seeing why it was written this way. In fact, I cannot even understand the rational for why it was originally written in groovy either. But its groovy now so any improvements would be greatly appreciated.

I'll eventually try to do so myself but I don't work on groovy enough to be super slick about it :)

@jglick
Copy link

jglick commented Aug 18, 2023

Well, at any rate just updating to 1.10.14 (once it is released) ought to fix this issue.

@jglick
Copy link

jglick commented Aug 21, 2023

https://ant.apache.org/ released yesterday

@hazendaz
Copy link
Member

fixed on 'spotbugs' branch now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants