Error in JDK 16 #537
Replies: 13 comments 31 replies
-
I've had the same problem: I found this solution |
Beta Was this translation helpful? Give feedback.
-
Can you please turn on verbose logging (call JDK 16 has started enforcing encapsulation, which is breaking things that use reflection all over the Java ecosystem. However, I tried running all the hundreds of ClassGraph unit tests on JDK 16, and they all pass. So we have to dig deeper to figure out what's going on. Thanks. The issue here is that |
Beta Was this translation helpful? Give feedback.
-
One issue here (but not the one you're running into) is that
should instead be:
|
Beta Was this translation helpful? Give feedback.
-
I think the
Whereas in JDK 16, this jar is not on the classpath:
And on JDK 16, for this project, the jar So the problem is not a ClassGraph problem (I think??), it appears to be a classpath problem. However if other code in the project is able to see and use the Are you able to provide a minimal reproducer project, please? |
Beta Was this translation helpful? Give feedback.
-
@worldbiomusic OK, I figured out what is going on here... Paper uses the Paperclip library to patch the original server jar. It then adds the patched jar to the classpath in a very weird way, by using a Java agent, and by calling This causes (by stepping through a native code method) This causes the jar to be added to Unfortunately the JDK 16 implements strong encapsulation of JDK internals, so there is absolutely no way to get the jar that was added to the classpath from this field. (It is possible to launch with the JVM commandline option This use of However, there is a workaround you could use: read the value of the property However, you can't use the That should do the trick... let me know! |
Beta Was this translation helpful? Give feedback.
-
So if your
then you need to derive the following URL (in a cross-platform way, maybe by converting to a
then add that URL to ClassGraph by calling After that, your existing code should work, including this classloading code: |
Beta Was this translation helpful? Give feedback.
-
With Burningwave it works (OpenJDK 64-Bit Server VM 16+36-2231). I obtain only an exception that is not important for your purpose and that will be solved in the next release in september (as a workaround you can put inside the bw-core.jar a burningwave.properties file that must contain this: |
Beta Was this translation helpful? Give feedback.
-
@JJBRT if this works with @burningwave, then Burningwave must be scanning more than just the classpath, because the patched jar is not even on the classpath, as I illustrated in my earlier comment. So How does Burningwave determine what to scan here? As far as I can see the only path criteria that are given is via |
Beta Was this translation helpful? Give feedback.
-
@worldbiomusic here's some example code that might solve your problem with ClassGraph. (I'm still waiting for @burningwave to respond explaining how Burningwave Core is able to find the patched jar, but as far as I can determine, something like the following is absolutely required in this case to find the classes in the patched jar, since it's not on the normal classpath.) List<URL> cachedDirJarURLs = new ArrayList<>();
for (String cpEntry : System.getProperty("java.class.path").split(File.pathSeparator)) {
File cpFile = new File(cpEntry);
if (cpFile.canRead()) {
File cachedDir = new File(cpFile.isDirectory() ? cpFile : cpFile.getParentFile(), "cached");
if (cachedDir.canRead() && cachedDir.isDirectory()) {
try {
for (File cachedDirJar : cachedDir.listFiles()) {
if (cachedDirJar.getName().toLowerCase().endsWith(".jar")) {
cachedDirJarURLs.add(cachedDirJar.toURI().toURL());
}
}
} catch (MalformedURLException e) {
// Ignore
}
}
}
}
ClassGraph classGraph = new ClassGraph();
if (!cachedDirJarURLs.isEmpty()) {
classGraph.addClassLoader(new URLClassLoader(cachedDirJarURLs.toArray(new URL[0])));
} |
Beta Was this translation helpful? Give feedback.
-
@worldbiomusic I just thought of something else you could try. Please try the following, without the changes I suggested above for finding the patched jar. Instead just call This will create a placeholder I totally forgot about this mechanism! But this was designed to solve exactly this sort of problem. It should work for superclasses, interfaces, and annotations that are named but not found during the scan. |
Beta Was this translation helpful? Give feedback.
-
keep in mind that the classloader you are using with Classgraph**:
... Is a new URLClassloader which is not the same Classloader that the server will use to load the classes and therefore events may not be intercepted. And Burningware Core seems to try to find all files. As mentioned here in the official documentation: "If no path will be passed to SearchConfig, the scan will be executed on the paths indicated by the 'paths.hunters.default-search-config.paths' property of the burningwave.properties file that has the following default value":
IF YOU NEED TO SCAN ONLY ONE OR SOME JARS YOU MUST SPECIFY IT:
Try it and tell us how long it takes and **check also that classes count returned by Classgraph and by Burningwave Core is the same. |
Beta Was this translation helpful? Give feedback.
-
Followup: @worldbiomusic tested the |
Beta Was this translation helpful? Give feedback.
-
@JJBRT I spoke with Roberto Gentili (@burningwave) and I am very happy to report I was completely wrong. Roberto is a genius, and he did in fact find a way to achieve what neither I nor anyone else in the Java world has been able to achieve. It's such a subtle and clever trick that I didn't even understand how it worked until he explained the code. He has generously offered to let me use his code in ClassGraph, so ClassGraph will be able to handle this highly unusual corner case (of Java agents extending the classpath). Grazie, Roberto! |
Beta Was this translation helpful? Give feedback.
-
Hello
I have used calssgraph library for Minecraft Bukkit API classes without problems.
But after Minecraft 1.17 update forced users to use JDK 8 to 16 and I have this error.
Error
registerAllEventHandler()
java code (from Minecraft Spigot Forum)Java code
How can i fix it?
Beta Was this translation helpful? Give feedback.
All reactions