classgraph / classgraph

An uber-fast parallelized Java classpath scanner and module scanner.
MIT License
2.76k stars 289 forks source link

classgraph cannot scan all files of guava 33.2.1 #861

Closed sebthom closed 4 months ago

sebthom commented 4 months ago

when upgrading guava from 33.2.0 to 33.2.1 classgraph suddenly cannot find 9 of guava classes

I am using classgraph like this:

try (ScanResult scanResult = new ClassGraph() //
   .enableAllInfo() //
   .enableSystemJarsAndModules() //
   .acceptPackages("com.google.common") //
   .verbose() //
   .scan() //
) {
  // ...
}

Results e.g. in:

2024-06-04T13:10:51.571+0200    ClassGraph  ---- Found classfile within subpackage of accepted package: com/google/common/base/Joiner.class
2024-06-04T13:10:51.695+0200    ClassGraph  ------ Parsing classfile (took 0,002352 sec)
2024-06-04T13:10:51.697+0200    ClassGraph  -------- Invalid classfile: Class com.google.common.base.Joiner has unknown method type annotation target 0x10: element size unknown, cannot continue reading class. Please report this at https://github.com/classgraph/classgraph/issues

and

2024-06-04T13:10:51.577+0200    ClassGraph  ---- Found classfile within subpackage of accepted package: com/google/common/collect/ArrayTable.class
2024-06-04T13:10:51.716+0200    ClassGraph  ------ Parsing classfile (took 0,001407 sec)
2024-06-04T13:10:51.717+0200    ClassGraph  -------- Invalid classfile: Class com.google.common.collect.ArrayTable has unknown method type annotation target 0x10: element size unknown, cannot continue reading class. Please report this at https://github.com/classgraph/classgraph/issues

I am using these dependencies:

<dependency>
  <groupId>io.github.classgraph</groupId>
  <artifactId>classgraph</artifactId>
  <version>4.8.172</version>
</dependency>
<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>33.2.1-jre</version>
</dependency>
lukehutch commented 4 months ago

Oh boy... this is due to a compiler bug in whatever compiler Google used to compile guava (which is probably some fork of Java that Google has been maintaining a massive patch set against for many years...).

The target type of 0x10 (which means "type in extends clause of class or interface declaration, or in implements clause of interface declaration") is only ever supposed to be added to ClassFile targets (i.e. this should only be used in class annotations), but the exception that you ran into shows that Google's compiler added an annotation tagged with this type to a method_info target too.

https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.20-420

I saw one of these issues before, with the Oracle compiler adding field annotations to methods, for the new record types. I fixed that by just ignoring these wrong annotations.

https://github.com/classgraph/classgraph/blob/cb447645be7365d1c213f305b37f0ad80326b4bc/src/main/java/io/github/classgraph/Classfile.java#L1567

I'll have to do the same with this one...

lukehutch commented 4 months ago

Should be fixed in 4.8.173 (unless the buggy compiler also output something else inappropriate in this case!). Thank you!

sebthom commented 4 months ago

Thanks for the quick fix!

lukehutch commented 4 months ago

@sebthom You're welcome!