From 51a0476667d551474b26cf20d111a83d81da4171 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Sat, 4 Dec 2010 20:49:18 +0000 Subject: [PATCH] [MNG-4925] Mismanagement of container lookup realm can cause type incompatibilities for plugins looking up components by string git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@1042237 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/DefaultBuildPluginManager.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java index 371f94cc56..22822233e7 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultBuildPluginManager.java @@ -86,8 +86,10 @@ public class DefaultBuildPluginManager throw new PluginExecutionException( mojoExecution, project, e ); } - ClassRealm oldLookupRealm = container.getLookupRealm(); + ClassRealm oldLookupRealm = container.setLookupRealm( pluginRealm ); + ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader( pluginRealm ); MavenSession oldSession = legacySupport.getSession(); @@ -95,8 +97,6 @@ public class DefaultBuildPluginManager { mojo = mavenPluginManager.getConfiguredMojo( Mojo.class, session, mojoExecution ); - Thread.currentThread().setContextClassLoader( pluginRealm ); - legacySupport.setSession( session ); // NOTE: DuplicateArtifactAttachmentException is currently unchecked, so be careful removing this try/catch! @@ -158,12 +158,8 @@ public class DefaultBuildPluginManager { mavenPluginManager.releaseMojo( mojo, mojoExecution ); - if ( oldLookupRealm != null ) - { - container.setLookupRealm( null ); - } - Thread.currentThread().setContextClassLoader( oldClassLoader ); + container.setLookupRealm( oldLookupRealm ); legacySupport.setSession( oldSession ); }