<div dir="ltr"><div dir="ltr"><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Sep 21, 2024 at 11:15 PM Rafael Winterhalter <<a href="mailto:rafael.wth@gmail.com">rafael.wth@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello,<br></div><div>It is a quite common need for Java agents to resolve class files for Java classes by their name. Normally, this is done by requesting a resource from the class loader. So if a class:</div><div><br></div><div>pkg.SampleClass</div><div><br></div><div>is requested, the agent calls ClassLoader.getResourceAsStream("pkg/SampleClass.class"). This normally works well, with a few exceptions where class loaders do not implement lookup.</div><div><br></div><div>However, with multi-release jars this is less reliable. In theory, on a Java 23 VM I would need to request all from:</div></div></blockquote><div><br></div><div>Rafael, </div><div><br></div><div>URLClassLoader::getResource already resolves the versioned class file entry, that is URLClassLoader::getResource will return the URL for "META-INF/versions/21/HelloWorld.class" when given the parameter "HelloWorld.class" with a multi-release JAR on the class path.</div><div><br></div><div>So since you're re-implementing version lookup yourself, I assume what you are experiencing here must be some third-party JAR-backed custom classloader overriding ClassLoader.findResource without properly taking versioned entries into account, right?</div><div><br></div><div>If that's the case, then the class file loaded would probably not be versioned correctly either, right? Also, if people can't override ClassLoader.findResource to support versioning, then I'd be surprised if they would override a new API point like getClassFileAsStream correctly.</div><div><br></div><div>Perhaps you could expand a bit why you need to implement the version lookup yourself? Which hole are you mending here?</div><div><br></div><div>Cheers,</div><div>Eirik.</div><div><br></div><div><br></div><div><br></div><div> </div></div></div>