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

Check fails with "Bundled signatures resource not found: jdk-unsafe-21" despite failOnUnsupportedJava/failOnViolation disabled #233

Closed
kohlschuetter opened this issue Sep 10, 2023 · 7 comments
Assignees

Comments

@kohlschuetter
Copy link

kohlschuetter commented Sep 10, 2023

When checking code that is compiled against Java 21 (or Java 22 fwiw), forbiddenapis Maven plugin 3.5.1 fails with the following error:

[ERROR] Failed to execute goal de.thetaphi:forbiddenapis:3.5.1:check (default) on project junixsocket-common: IO problem while reading files with API signatures.: Bundled signatures resource not found: jdk-unsafe-21 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal de.thetaphi:forbiddenapis:3.5.1:check (default) on project junixsocket-common: IO problem while reading files with API signatures.
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:333)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: org.apache.maven.plugin.MojoExecutionException: IO problem while reading files with API signatures.
    at de.thetaphi.forbiddenapis.maven.AbstractCheckMojo.execute (AbstractCheckMojo.java:452)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)
Caused by: java.io.FileNotFoundException: Bundled signatures resource not found: jdk-unsafe-21
    at de.thetaphi.forbiddenapis.Signatures.addBundledSignatures (Signatures.java:258)
    at de.thetaphi.forbiddenapis.Signatures.addBundledSignatures (Signatures.java:308)
    at de.thetaphi.forbiddenapis.Checker.addBundledSignatures (Checker.java:330)
    at de.thetaphi.forbiddenapis.maven.AbstractCheckMojo.execute (AbstractCheckMojo.java:415)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:283)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:226)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:407)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:348)

Here is my Maven configuration:

<plugin>
    <groupId>de.thetaphi</groupId>
    <artifactId>forbiddenapis</artifactId>
    <version>3.5.1</version>
    <configuration>
        <failOnUnsupportedJava>false</failOnUnsupportedJava>
        <excludes>
            <exclude>**/module-info.class</exclude>
        </excludes>
        <bundledSignatures>
            <bundledSignature>jdk-unsafe</bundledSignature>
            <bundledSignature>jdk-deprecated</bundledSignature>
            <bundledSignature>jdk-non-portable</bundledSignature>
        </bundledSignatures>
    </configuration>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>check</goal>
                <goal>testCheck</goal>
            </goals>
            <configuration>
                <failOnViolation>false</failOnViolation>
            </configuration>
        </execution>
    </executions>
</plugin>

java -version says:

openjdk version "22-ea" 2024-03-19
OpenJDK Runtime Environment (build 22-ea+14-1033)
OpenJDK 64-Bit Server VM (build 22-ea+14-1033, mixed mode, sharing)

Since failOnUnsupportedJava (and failOnViolation) is set to false, I would expect the checks to emit a warning at most and not fail instead. I also wonder if falling back to a supported version is a possibility (e.g., look for jdk-unsafe-21, jdk-unsafe-20, etc. if jdk-unsafe-22 is unavailable).

@kohlschuetter kohlschuetter changed the title Check fails with "Bundled signatures resource not found: jdk-unsafe-22" despite failOnUnsupportedJava/failOnViolation disabled Check fails with "Bundled signatures resource not found: jdk-unsafe-21" despite failOnUnsupportedJava/failOnViolation disabled Sep 10, 2023
@uschindler
Copy link
Member

Hi,

Java 21 signatures are not yet supported. It has nothing to do with the used java runtime. You configured signatures for java 21 (e.g. through compiler config). If they are not found, it is not a bug and wrongly configured settings always cause a failure.

Configure targetVersion property with the java version equal to compiler config (see documentation). Normally you would give the release/target version passed to compiler plugin. Normally you have targetVersion or releaseVersion configured on compiler plugin you need to do the same here.

FailOnUnsupportedJava does not trigger, because it is about bytecode version of scanned class files. This is unlikely to trigger nowadays.

Fail on violation has nothing to do with this issue.

@uschindler
Copy link
Member

P.S. support for signatures will come soon, the release is planned a few days after Java 21 comes out.

@kohlschuetter
Copy link
Author

@uschindler If I understand you, being — at least passively — forward compatible to new Java versions is a non-goal?

Isn't this a bug as "failOnUnsupportedJava" is supposed to take care of that scenario?

@uschindler
Copy link
Member

uschindler commented Sep 10, 2023

Java 21 bytecode is already supported.

The problem is that signatures files are not yet available. As you cannot foresee the future (you need to carefully check diffs), there is the problem that uptodate signatures for deprecated and unsafe apis can only be provided after release of the corresponding java version. There's already a few issues for preparing them.

As said before: failOnUnsupportedJava is a legacy feature that only prevents looking into jdk internals in early java versions. It has nothing to do with signature files. The java runtime version is irrelevant for parsing them or checking class files. In short: Since Java 9 this is a non-issue as module system is used to get public method signatures and runtime class file parsing is no longer needed. The option will possibly go away once java 7 support is removed.

Actually forbidden apis works perfectly fine with Java 21 or 22, there are just no updated signatures provided yet, which can't be done before it's released.

The problem you have is a configuration problem. If you would specify the target java version in your build file, it won't fallback to runtime defaults.

The issue here is that there are no forbidden signatures for Java 21 yet. As workaround use the ones of Java 20.

@kohlschuetter
Copy link
Author

I see.

Specifying <releaseVersion>20</releaseVersion> in the forbiddenapis Maven plugin <configuration> section did the trick.

@uschindler
Copy link
Member

I deleted the last comment, sorry. You said "did the trick".

There are some plans to add a compatibility layer for newer signatures files automatactially falling back to previous versions and to also simplify the "include" chains in the current variants.

There is also the issue that for code compiled against Java 21, we need to remove one specific signature from the unsafe ones (it was fixed upstream) and there's no support for that (see #225).

@uschindler
Copy link
Member

P.S.: I am on vacation this week, sorry for short answers only.

kohlschuetter added a commit to kohlschutter/kohlschutter-parent that referenced this issue Sep 20, 2023
When forbidden-apis is too old to support a certain Java version (e.g.,
21), we can override the release compliance level via a Maven property
and forcibly specify a lower Java version via
"forbiddenapis.releaseVersion".

This may not always work, but is better than nothing.

policeman-tools/forbidden-apis#233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants