yWorks / yGuard

The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts
https://yworks.github.io/yGuard/
MIT License
367 stars 59 forks source link

Exception when obfuscating: java.lang.UnsupportedOperationException: PermittedSubclasses requires ASM9 #156

Closed clintsb111 closed 1 month ago

clintsb111 commented 1 month ago

We are upgrading from Java 8 to Java 21. I can successfully obfuscate most classes but I have one that triggers the following error.

D:\release\java21\build\dcmd\xml\build.xml:735: java.lang.UnsupportedOperationException: PermittedSubclasses requires ASM9         at org.objectweb.asm.ClassVisitor.visitPermittedSubclass(ClassVisitor.java:281)         at org.objectweb.asm.ClassReader.accept(ClassReader.java:707)         at org.objectweb.asm.ClassReader.accept(ClassReader.java:425)         at com.yworks.yshrink.core.Analyzer.visitAllClasses(Analyzer.java:109)         at com.yworks.yshrink.core.Analyzer.initModel(Analyzer.java:67)         at com.yworks.yshrink.YShrinkModelImpl.createSimpleModel(YShrinkModelImpl.java:38)         at com.yworks.yguard.ObfuscatorTask.addInheritanceEntries(ObfuscatorTask.java:1399)         at com.yworks.yguard.ant.ExposeSection.createEntries(ExposeSection.java:304)         at com.yworks.yguard.ObfuscatorTask.execute(ObfuscatorTask.java:1160)         at com.yworks.yguard.YGuardTask.execute(YGuardTask.java:118)         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)         at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)         at java.base/java.lang.reflect.Method.invoke(Method.java:580)         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)         at org.apache.tools.ant.Task.perform(Task.java:350)         at org.apache.tools.ant.Target.execute(Target.java:449)         at org.apache.tools.ant.Target.performTasks(Target.java:470)         at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)         at org.apache.tools.ant.Project.executeTarget(Project.java:1374)         at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)         at org.apache.tools.ant.Project.executeTargets(Project.java:1264)         at org.apache.tools.ant.Main.runBuild(Main.java:818)         at org.apache.tools.ant.Main.startAnt(Main.java:223)         at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)         at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)

I have attempted to ask yguard to ignore the file causing the error but unfortunately, this hasn't worked.

Version information openjdk version "21.0.3" 2024-04-16 LTS OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS) OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing) yguard-bundle-4.1.0.zip apache-ant-1.10.14-bin.zip

I have copied all three jar files in the guard bundle to the ant lib folder.

Thank you!

clintsb111 commented 1 month ago

I mentioned that I tried to get yguard to ignore the offending class. This would be a workaround that we could live with. The class was in the widgets folder. This is the ant task I am using.

<target name="obfuscateCS" if="exists.CommandStation" description="obfuscate the cs distribution" >

</target>
thomasbehr commented 1 month ago

The problem is most likely <class implements="java.io.Serializable" .../> element in your <keep> section.

You probably need to determine all classes that implement Serializable in some other way and then exclude those from obfuscation using a <patternset>.

Alternatively, you could try changing the ASM level in the yGuard sources to ASM9 and recompiling yGuard from source. I have not yet tested if that solves the issue without introducing other problems, so I cannot tell for certain that this will work. However, the ASM level is only specified in two files ModelVisitor and OutputVisitor and only ModelVisitor is involved when obfuscating but not shrinking.

clintsb111 commented 1 month ago

I checked out your changes and built a yguard-4.1.1 jar. This worked for me. Thank you so much for your astonishingly fast response!

thanhminh-vht commented 1 month ago

@thomasbehr I got a similar issue (Record requires ASM8), but it seem to have been fixed by the commit. Can you release the fix to maven as a new version?

thomasbehr commented 1 month ago

yGuard 4.1.1 has been pushed to Maven Central.