Guardsquare/proguard

Support for Java 22

xberkhout opened this issue ยท 18 comments

As the first release candidate of Java 22 has arrived (https://openjdk.org/projects/jdk/22/) it would be nice if support would be added in the next patch/release. I hope it is just changing the allowed class file version to 66. Maybe directly do it for Java 23 so 67 (https://javaalmanac.io/bytecode/versions/) as early access build for Java 23 are also available (https://jdk.java.net/23/).

I would like to try out the new JEP 454: Foreign Function & Memory API and use it in my build process.

It looks like none of the features or changes in Java 22 require any special handling by ProGuard beyond the version number (e.g. no new attributes, bytecode instructions).

Could you make a PR with the required changes, similar to the changes made for Java 21? Guardsquare/proguard-core#92

I do not understand. You say it is very easy and you ask me to make a Pull Request? I am not familiar with the code and GitHub policies, so for me it is a lot of work finding out what you mean and how to do that. I can wait, but I would hope there is an update when JDK 22 releases on March 19. I am not requesting special favors only that Proguard is compatible with the current JDK and maybe even with the EA when there is a release candidate.

henm commented

I would also like to use Java 22 with proguard, so I created a PR similar to the one for Java 21 mentioned above: Guardsquare/proguard-core#127

Thanks!

The changes made by @henm have been merged already. Can we also expect a release in the near future :-? That would be great.

The support to Java 22 urges!

Caused by: java.lang.UnsupportedOperationException: Unsupported version number [66.0] (maximum 65.65535, Java null)

Please as soon as possible! We need ๐Ÿš€

Thank you ๐Ÿ™Œ

Came here as well to look for a release date on the Java 22 support in maven! I am currently migrating the application from Java 8 to 22 and found out it uses proguard and now I am stuck on the final step before being able to release :(

@lordarnoud to bypass this issue and not delay the releases, what I made was compile with Java 21 and then flawless run with Java 22.

It is not how we like to work, but until the new Proguard comes out, the only way to run with Java 22 is by compiling to Java 21.

Of course, it is very bad for us programmers because we are unable to use in the source code any new feature of Java 22 yet... ๐Ÿ˜ญ

But at least in production, we can benefit from Java 22! ๐Ÿš€

I just stumbled across the same problem. I made a tool that can change classfile version in one go in directories/zip archives/single files.
It only changes version of the class, no actual backporting is done.
The command line syntax is ... majorVersionFrom majorVersionTo file1 file2 file3 "file4"
(majorVersion is the JDK version, not classfile version)
Example use is as follows (Change version in shadow jar, from 22 to 21):

val changeVersion = tasks.register<JavaExec>("changeVersion") {
    javaLauncher.set(javaToolchains.launcherFor {
        languageVersion.set(JavaLanguageVersion.of(17))
    })
    classpath(project.file("versionchanger.jar"))
    mainClass.set("dev.xdark.versionchanger.CLI")

    args(
        listOf("22", "21") + listOf(project1, project2, project3)
                .map { it.tasks.shadowJar.get().archiveFile.get().asFile.absolutePath }
    )
}

Hope someone finds this useful.

@xxDark What makes you think that an incompatible class file gets compatible by just changing a number in it? This may just lead to difficult to trace crashes.

@xxDark What makes you think that an incompatible class file gets compatible by just changing a number in it? This may just lead to difficult to trace crashes.

Nothing makes me think that. That is why I put the text in bold.
JDK 22 classfile format did not change (correct me if I'm wrong), and I needed to use Proguard with it. It did not work, so I made that fast tool to change all classfile versions for me.
I'm well aware that classfiles don't get compatible by just changing their major version.

Is there a release date in sight for this? :) Or any updates on it?

ProGuard 7.5 has just been published with Java 22 support

Awesome! Thank you!

Thanks a lot!

When I try to package using JDK 17 and ProGuard 7.5.0 and proguard-core is 9.1.1 , I encounter an error

  1. Caused by: java.lang.UnsupportedOperationException: Unsupported version number [66.0] (maximum 65.65535, Java null),
  2. Caused by: java.io.IOException: Can't process class [org/apache/tomcat/util/net/openssl/panama/OpenSSLContext$1.class] (Unsupported version number [66.0] (maximum 65.65535, Java null))
    3.java.io.IOException: Can't read [D:\installation\JavaRepository\org\apache\tomcat\embed\tomcat-embed-core\10.1.24\tomcat-embed-core-10.1.24.jar(;;;;;;;;!META-INF/,!META-INF/versions/17/.class)] (Can't process class [org/apache/tomcat/util/net/openssl/panama/OpenSSLContext$1.class] (Unsupported version number [66.0] (maximum 65.65535, Java null)))

How should I resolve this issue? What could be the reasons behind it?

Hi @Chinaniu ! You are using an older version of ProGuardCORE 9.1.1 that doesn't support JDK 22. JDK 22 support was added in ProGuardCORE 9.1.2 and ProGuard 7.5 has a dependency on ProGuardCORE 9.1.4.

When attempting to launch the obfuscated Spring Boot project built with JDK 17 using ProGuard, an error message is encountered during startup. this is a error Description:

Description:

Web application could not be started as there was no org.springframework.boot.web.servlet.server.ServletWebServerFactory bean defined in the context.

Action:

Check your application's dependencies for a supported servlet web server.
Check the configured web application type.

then this is my proguard configuration

-dontshrink

-dontoptimize

-useuniqueclassmembernames

-adaptclassstrings

#-keepparameternames

-keepclassmembers public class * {
void set*(**);
*** get
();
}

-keepclassmembers class * implements java.io.Serializable {
*;
}

-keep class *{
@org.springframework.beans.factory.annotation.Autowired *;
@org.springframework.beans.factory.annotation.Value *;
}

-keepclassmembers class * {
public static void main(java.lang.String[]);
}

-keep public class * extends org.springframework.boot.web.servlet.server.ServletWebServerFactory { *; }

-ignorewarnings
-dontnote

-printconfiguration

-printseeds

Hi @Chinaniu , for usage questions like that please head over to the Guardsquare community to continue the discussion where you can get tips and advice on your configuration from our team of engineers and skilled community members.

You'll also find some useful information in the manual in how to configure ProGuard.