From eb7cdefaaa90143b55c70febf5e67e14831fdb38 Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 13 Apr 2023 11:56:13 +0200 Subject: [PATCH] [MNG-7759] Maven2 plugins will not have even session setter (#1084) As setter was added in Maven3. Still, this causes unexpected NPE during plugin execution, while Maven3 should support Maven2 plugins. --- https://issues.apache.org/jira/browse/MNG-7759 --- .../java/org/apache/maven/project/DefaultProjectBuilder.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index 00498cf39c..9fa8f3c22b 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -1000,6 +1000,10 @@ public class DefaultProjectBuilder implements ProjectBuilder { } private ModelCache createModelCache(RepositorySystemSession session) { + // MNG-7759: very old clients (Maven2 plugins) will not even have session, as setter was added in Maven 3 + if (session == null) { + return null; + } // MNG-7693: for older clients (not injecting ModelCacheFactory), make this work OOTB w/ defaults return modelCacheFactory != null ? modelCacheFactory.createCache(session)