ClassLoader API to look up class files
Rafael Winterhalter
rafael.wth at gmail.com
Sun Sep 22 16:45:51 UTC 2024
That is only true for Class::getResource which resolves resources relative
to the loaded class's class file location. Java agents typically use
ClassLoader::getResource(AsStream) as the loaded class is not available in
the general case of transforming, and not retransforming, a class. For
example, when instrumenting a newly loaded class A in a
ClassFileTransformer, it might not be the case that its superclass B is
loaded. If class B exists in two versions as part of a multi-release jar
file, currently, you need to query the class loader of A as the JVM would
do. When loading a class, ClassLoader::findClass respects the multi-release
characteristic. But for ClassLoader::getResource, this is not the case.
This is why I want to suggest a new method where this is possible, as the
intend to resolve a class file is explicit. Currently, you need to iterate
as the ClassLoader does not expose any relevant information.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20240922/a9ede7f8/attachment.htm>
More information about the core-libs-dev
mailing list