diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultLegacySupport.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultLegacySupport.java index dfd3f40a47..aea096316e 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultLegacySupport.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultLegacySupport.java @@ -37,23 +37,29 @@ public class DefaultLegacySupport implements LegacySupport { - private ThreadLocal session = new InheritableThreadLocal(); + private static final ThreadLocal session = new InheritableThreadLocal(); public void setSession( MavenSession session ) { if ( session == null ) { - this.session.remove(); + MavenSession[] oldSession = DefaultLegacySupport.session.get(); + if ( oldSession != null ) + { + oldSession[0] = null; + DefaultLegacySupport.session.remove(); + } } else { - this.session.set( session ); + DefaultLegacySupport.session.set( new MavenSession[] { session } ); } } public MavenSession getSession() { - return session.get(); + MavenSession[] currentSession = DefaultLegacySupport.session.get(); + return currentSession != null ? currentSession[0] : null; } public RepositorySystemSession getRepositorySession()