On 17/03/2026 18:25, Some Java user wrote:


The reason is that `appendToBootstrapClassLoaderSearch` requires a JarFile, i.e. a file on disk. However, callers of it often only want to add a few specific classes to the bootstrap class loader and therefore resort to creating a temp JAR containing only those classes (example [1]).
Alternatives are error-prone:

  * Adding the enclosing JAR file (1) is error prone when having to
    use `Class#getProtectionDomain` or similar to determine the JAR
    file path first and (2) includes a lot of classes which should not
    be added to the bootstrap class loader (an even bigger problem
    when the `appendToBootstrapClassLoaderSearch` call is in a
    library, and users might have repackaged/shaded that library,
    including even more unrelated classes).
  * Trying to create the JarFile only once and reusing it is
    error-prone for concurrent JVM processes, where one might see an
    incomplete JarFile then.

So the effect is that an agent has to create a new temp JarFile every time when using `appendToBootstrapClassLoaderSearch`.

How often is appendToBootstrapClassLoaderSearch called in a single run? Is the thing that execute the VM with -javaagent in a script or POM configuration? If the agent is create a temporary JAR file to put on the boot class path then I'm wondering why it can't be given its own directory to do this, and then cleanup after the test run is complete.

-Alan

Reply via email to