Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid classfile: Unknown constant pool tag 17 (element size unknown, cannot continue reading class) #527

Closed
haoyuf opened this issue Jun 6, 2021 · 6 comments

Comments

@haoyuf
Copy link

haoyuf commented Jun 6, 2021

Java version: JDK 11.0.11
ClassGraph version: 4.8.47

Hey, I found a really tricky issue in our team code when we tried to upgrade from JDK8 to JDK11.

The error as in the title happened when we tried to scan the classes under certain package prefix.
Below is the code we run and the error logs.

ScanResult result = new ClassGraph().enableAllInfo().verbose()
                .whitelistPackages(prefix).scan();  
[java] 2021-06-06T16:58:06.424-0400	ClassGraph	------------ Found classfile within whitelisted package: s3/heart/activities/ExecutionEnvironment.class
[java] 2021-06-06T16:58:06.517-0400	ClassGraph	-------------- Parsing classfile (took 0.008992 sec)
[java] 2021-06-06T16:58:06.526-0400	ClassGraph	---------------- Invalid classfile: Unknown constant pool tag 17 (element size unknown, cannot continue reading class). Please report this at https://github.com/classgraph/classgraph/issues

The tricky thing is, it only happened when we tried to use JDK11 and scan cross Jars. It works totally fine if we are using JDK8 or if we only scan inside the same jar which ClassGraph sits. Wondering do you have any clue? If it requires to upgrade ClassGraph, we need to talk to other teams to do it. Anything we can try out before that? Thanks!

Best

lukehutch added a commit that referenced this issue Jun 6, 2021
@lukehutch
Copy link
Member

Hi @haoyuf,

Thanks for the bug report. It looks like what happened is that constant pool tag numbers 1-20 were added up to JDK 9, but then in JDK 11, for some weird reason they went back and used an unused tag number 17.

The reason why ClassGraph can't keep scanning with an unknown tag number is that it doesn't know how big the corresponding constant pool entry is, which throws off reading of the rest of the classfile, because the classfile format was not well designed to support forwards compatibility by just skipping over unknown information. (I argued long and hard with the JVM team to fix this, and they pushed back by saying that if a library couldn't understand 100% of the classfile format, it had no business trying to parse the classfile, and that no assumptions could be made about future format changes, so every library that reads classfiles must be prepared to carefully check and conform to spec changes with the new 6-monthly release cadence, and push out a release at least every 6 months to keep up. I think their stance is ridiculous, but that's what they ruled!)

Tag 17 is used to "represent a dynamically-computed constant, an arbitrary value that is produced by invocation of a bootstrap method in the course of an ldc instruction, among others". I don't know what language feature(s) or what JVM language(s) would make use of that.

I fixed this by skipping over constant pool records corresponding to tag 17, since there's no useful information for ClassGraph in those records.

This is released in 4.8.108. Thank you / 谢谢!

@lukehutch
Copy link
Member

PS with this change, ClassGraph's support for constant pool tags is updated up to the most recent release, JDK 16. Hopefully adding a new constant pool tag is a rare occurrence.

@haoyuf
Copy link
Author

haoyuf commented Jun 7, 2021

Thanks a lot, this is really quick reply! I would like to try version 4.8.108!

@lukehutch
Copy link
Member

I try to turn around bugfixes quickly, because almost no other open source project ever does! :-) This should fix the problem, but let me know if you run into further issues. Thanks for the report!

@haoyuf
Copy link
Author

haoyuf commented Jun 11, 2021

Hey, Luke. Just FYI. Your commit fixed the issue!

@lukehutch
Copy link
Member

Great, thank you for confirming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants