<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <br>
    <br>
    <div class="moz-cite-prefix">On 14/03/2025 10:54, Simone Bordet
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:CAFWmRJ0aA07cCMraPbjU5=MmgBg3qqJzfKuK_hP8dRrJicQkxA@mail.gmail.com">
      <pre class="moz-quote-pre" wrap="">:

The question is whether there is a way for a child ModuleLayer to
perform the equivalent of "--add-modules", but programmatically at
runtime, that would add the module to the graph?</pre>
    </blockquote>
    <br>
    Module layers are immutable so you can't modify the boot layer at
    runtime. <br>
    <br>
    In this case, the initial module is a named module that doesn't
    transitively require java.instrument so that module is not in the
    boot layer. If they server was started with -javaagent then the
    java.instrument would be in the boot layer.  In JEP 261 the
    recommendation for container apps, like this one, is to run with
    --add-module ALL-DEFAULT and it will ensure that any module in the
    run-time that exports an API will be in the boot layer.<br>
    <br>
    A comment in passing is that it's surprising that there are modules
    in ee$N layers requiring java.instrument. The classes in this
    modules aren't normally used by libraries and applications, instead
    they work as the side channel for agents.<br>
    <br>
    <span style="white-space: pre-wrap">
</span>
    <blockquote type="cite" cite="mid:CAFWmRJ0aA07cCMraPbjU5=MmgBg3qqJzfKuK_hP8dRrJicQkxA@mail.gmail.com">
      <pre class="moz-quote-pre" wrap="">
As a side question, I was wondering what is the benefit of using
ModuleLayers versus just using ClassLoaders.
I can think of earlier error detection: if the ModuleLayer is not
setup correctly (as above) I get an early error, which I would only
get much later at runtime if I was using ClassLoaders.</pre>
    </blockquote>
    Right, that's part of reliable configuration where errors are
    detected in pre-flight checks rather than failing mid-flight. The
    other part is strong encapsulation. ClassLoader can provide
    isolation but they are just part of the setup as class loaders
    otherwise just load classes.<br>
    <br>
    -Alan<br>
  </body>
</html>