Skip to content

Commit

Permalink
[MNG-6275] Maven Embedder compatible fix
Browse files Browse the repository at this point in the history
- Embedded sets up a classloader to mimic the boot classpath based on parsing the classworldConf
- This 'bootLoader' is then installed as the context classloader in the current thread
- By default, a running JVM will start with a thread context classloader of 'null' to indicate the
  system classloader should be used
- This change switches to follow the 'correct' behaviour of following the context classloader
  and falling back to the system class loader only in the case where the context classloader is
  null.
- For running from the CLI, we expect that the thread context classloader will always be null
  so this should be as before
- For running from embedder, we expect that the thread context classloader will have been correctly
  configured, so this should behave as intended
  • Loading branch information
stephenc authored and gnodet committed Jan 3, 2022
1 parent 486712a commit efdde34
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -120,7 +120,9 @@ private ClassRealm newRealm( String id )
{
try
{
ClassRealm classRealm = world.newRealm( realmId, PARENT_CLASSLOADER );
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
ClassRealm classRealm = world.newRealm( realmId, contextClassLoader == null
? PARENT_CLASSLOADER : contextClassLoader );

if ( logger.isDebugEnabled() )
{
Expand Down

0 comments on commit efdde34

Please sign in to comment.