HanSolo / jdktools

JDKTools is a library that contains tools related to system info and versioning
5 stars 0 forks source link

JAR file validation fails #1

Open sormuras opened 2 years ago

sormuras commented 2 years ago

Hi Gerrit,

Running jar --validate --file jdktools-17.0.4.jar using jdk of JDK 17 (17.0.1, 17.0.2), 18 RC, and 19-ea yields:

java.lang.UnsupportedOperationException: This feature requires ASM9_EXPERIMENTAL
        at java.base/jdk.internal.org.objectweb.asm.ClassVisitor.visitPermittedSubclassExperimental(ClassVisitor.java:299)
        at java.base/jdk.internal.org.objectweb.asm.ClassReader.accept(ClassReader.java:715)
        at java.base/jdk.internal.org.objectweb.asm.ClassReader.accept(ClassReader.java:432)
        at jdk.jartool/sun.tools.jar.FingerPrint.getClassAttributes(FingerPrint.java:165)
        at jdk.jartool/sun.tools.jar.FingerPrint.<init>(FingerPrint.java:81)
        at jdk.jartool/sun.tools.jar.Validator.getFingerPrint(Validator.java:142)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.zip.ZipFile$EntrySpliterator.tryAdvance(ZipFile.java:558)
        at java.base/java.util.Spliterator.forEachRemaining(Spliterator.java:332)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
        at jdk.jartool/sun.tools.jar.Validator.validate(Validator.java:83)
        at jdk.jartool/sun.tools.jar.Validator.validate(Validator.java:74)
        at jdk.jartool/sun.tools.jar.Main.validateJar(Main.java:446)
        at jdk.jartool/sun.tools.jar.Main.run(Main.java:424)
        at jdk.jartool/sun.tools.jar.Main.main(Main.java:1698)

I am not sure what the underlying issue is.

It seems to related to experimental/preview features of ASM. Does jdktools use incubating and/or preview features?

aalmiray commented 2 years ago

Did the following steps:

Same error. However if the bnd plugin is commented out I get a different error

$ jar --validate --file build/libs/jdktools-17.0.4.jar 
java.lang.UnsupportedOperationException: This feature requires ASM8
HanSolo commented 2 years ago

@sormuras Nope, it should only be released features...no experimental so far...at least that's the settings in Intellij, so I guess it would also complain if there would be experimental features used. I also cleaned it up a bit, still contained unused stuff but I get the same error that @aalmiray mentioned..."This feature requires ASM8"

HanSolo commented 2 years ago

I've created a complete new project and only copied the .java files using no gradle plugins at all...and it leads to the same error "This feature requires ASM8". Also replace the one record that I use by a class did not fix it, so at the moment I have no idea why it fails...

sormuras commented 2 years ago

Tried the following steps with the source from this project:

And it also produces:

 java.lang.UnsupportedOperationException: This feature requires ASM9_EXPERIMENTAL
        at java.base/jdk.internal.org.objectweb.asm.ClassVisitor.visitPermittedSubclassExperimental(ClassVisitor.java:299)
        at java.base/jdk.internal.org.objectweb.asm.ClassReader.accept(ClassReader.java:715)
        at java.base/jdk.internal.org.objectweb.asm.ClassReader.accept(ClassReader.java:432)
        at jdk.jartool/sun.tools.jar.FingerPrint.getClassAttributes(FingerPrint.java:165)
        at jdk.jartool/sun.tools.jar.FingerPrint.<init>(FingerPrint.java:81)
        at jdk.jartool/sun.tools.jar.Validator.getFingerPrint(Validator.java:142)

Something's off here... 🤔

HanSolo commented 2 years ago

Took the jdk11 branch and did the same...and it works...

sormuras commented 2 years ago

"Getting closer..."

HanSolo commented 2 years ago

I think I have something...I've compiled the jdk11 branch with Zulu 11 and it works...then I compiled the jdk11 branch with Zulu 17 and it fails...

HanSolo commented 2 years ago

Will now try with Temurin 17.0.2...

HanSolo commented 2 years ago

Same thing...with Temurin 17.0.2 and the main branch it also fails...

aalmiray commented 2 years ago

This might be a change in later JDKs as it works on 11

HanSolo commented 2 years ago

I will now give 16.0.2 a try...

sormuras commented 2 years ago

Created https://bugs.openjdk.java.net/browse/JDK-8282446 to track this JDK-related issue.

HanSolo commented 2 years ago

16.0.2 also fails...

aalmiray commented 2 years ago

Removing all JDK17 syntax makes jar --validate work. It's one of:

HanSolo commented 2 years ago

Yep I've already tried to remove record and Stream.toList() so it seems to be the switch...will try...

HanSolo commented 2 years ago

And I guess the comma separated case statements are the problem...

aalmiray commented 2 years ago

Yes, they might be. There's a lot of them (easy on the sugar boy 😏 )

sormuras commented 2 years ago

It's all of those not covered by Opcodes.ASM7: https://github.com/openjdk/jdk/blob/master/src/jdk.jartool/share/classes/sun/tools/jar/FingerPrint.java#L246-L248