Class version updated to JDK9 (53.0) while exporting jar with Recaf using JDK8
I'm using Oracle JDK 1.8.0_333 to run Recaf but if edit bytecode inside a Jar and export it I get some class updated to JDK9 (53.0) and I can't run the jar with Java 1.8
Exception
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/bouncycastle/jce/provider/BouncyCastleProvider has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:650)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:632)
Screenshots
Recaf does not update any class versions, send sample and we will take a look (if you have legal rights, if you don't, make a PoC). To do that, join our Discord or send it here
That's weird I checked the mentioned class version before and after editing and it's definitely updated does has anything to do with the de-compiler config choice?
I will try to make a POC but I'm not sure if I can reproduce it
file org/bouncycastle/jce/provider/BouncyCastleProvider.class
org/bouncycastle/jce/provider/BouncyCastleProvider.class: compiled Java class data, version 49.0 (Java 1.5)
https://github.com/Col-E/Recaf/blob/master/src/main/java/me/coley/recaf/ui/controls/text/JavaEditorPane.java#L117 Recaf will use whatever version the class had before, but it will bump/lower it if javac does not support it. Minimum version Recaf requires is JDK 8, thus, it should not change anything
If you're willing, you can clone the project and open it in an IDE. Then set a breakpoint on the line where xxDark mentions. That would let you inspect where the wrong version is coming from and you can provide additional details from that.
For me, I've not personally encountered this (WorksForMe:tm:) so I'm not sure where its getting the wrong value from.
This is caused by the multi-class version feature.
https://docs.oracle.com/javase/10/docs/specs/jar/jar.html#multi-release-jar-files
Ah, so the workspace model needs to be updated.... 🙃
Yeah, been aware of this for awhile but its a difficult task that Ive been putting off.