Java 17 cannot access class sun.security.pkcs.PKCS7

Answered

I work with old project and I want it to support on any Java versions above 8, but when running with Java 17, I got this error

Exception in thread "main" java.lang.IllegalAccessError: class cc.binmt.signature.NKillSignatureTool (in unnamed module @0x17a7cec2) cannot access class sun.security.pkcs.PKCS7 (in module java.base) because module java.base does not export sun.security.pkcs to unnamed module @0x17a7cec2
    at cc.binmt.signature.NKillSignatureTool.getApkSignatureData(NKillSignatureTool.java:243)
    at cc.binmt.signature.NKillSignatureTool.main(NKillSignatureTool.java:37)

I have added

--add-exports=java.base/sun.security.x509=ALL-UNNAMED --add-exports=java.base/sun.security.pkcs=ALL-UNNAMED

in Java Compiler but still getting same error when running the app, it only fixed syntax errors

What should I do?

 

1
9 comments

This error is caused by the fact that sun.security module is no longer supported in Java 16 and higher. Try using the methods described here: https://openjdk.java.net/jeps/396 

Try adding the options you mentioned into "Additional Command line parameters"

0

Tried it, still getting same error

0

Share a sample project demonstrating the case including the .idea folder. You can use https://uploads.jetbrains.com for uploading

0

Ok, here is the project

Upload id: 2022_04_20_Wvdpqo8yczkx65nQ (file: ApkSignatureKiller-master.zip)

0

Add the the mentioned options to "VM options" field of run configuration https://i.imgur.com/j4v0Lcn.jpg

1

Thanks, it works now

0

Hi, I have added the VM options as suggested but getting ClassNotFoundException exception at runtime. Would you suggest me what dependencies I have to add. Thanks

Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/7.5/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk-17.0.4.1\bin\java.exe -XX:MaxMetaspaceSize=256m -XX:+HeapDumpOnOutOfMemoryError security.util=ALL-UNNAMED --add-exports=java.base/sun.security.pkcs=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.prefs/java.util.prefs=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xms256m -Xmx512m -Dfile.encoding=windows-1252 -Duser.country=IN -Duser.language=en -Duser.variant -cp C:\Users\RS\.gradle\wrapper\dists\gradle-7.5-bin\f1w0cc9nuo0eivz97x2xlu9sv\gradle-7.5\lib\gradle-launcher-7.5.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 7.5
Please read the following process output to find out more:
-----------------------
Error: Could not find or load main class security.util=ALL-UNNAMED
Caused by: java.lang.ClassNotFoundException: security.util=ALL-UNNAMED

-----------------------
Check the JVM arguments defined for the gradle process in:
 - gradle.properties in GRADLE_USER_HOME directory

 

0

Hello,

Seems you adding option in "Gradle" run configuration instead of "Application". If you need to use Gradle, then option should be passed via build script, for example org.gradle.jvmargs in gradle.properties file, see https://docs.gradle.org/current/userguide/build_environment.html

0

in my case I was using ojdbc8 with java 17, upgrading to ojava11 fixed the issue

0

Please sign in to leave a comment.