From a6ecbde9e97075038417324fbc79a7362a0b0362 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 8 Oct 2024 11:04:20 +0200 Subject: [PATCH] Fix concurrency issue in DefaultModelValidator (#1786) --- .../internal/impl/model/DefaultModelValidator.java | 7 ++++--- .../internal/DefaultPluginDependenciesResolver.java | 11 ++++------- .../project/DefaultProjectDependenciesResolver.java | 8 ++------ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java index c8e875be4bb2..94eb22f1dc4a 100644 --- a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java +++ b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java @@ -30,6 +30,7 @@ import java.util.Objects; import java.util.Optional; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.function.Supplier; import java.util.function.UnaryOperator; @@ -283,9 +284,9 @@ protected ActivationProperty.Builder transformActivationProperty_Value( } } - private final Set validCoordinatesIds = new HashSet<>(); + private final Set validCoordinatesIds = ConcurrentHashMap.newKeySet(); - private final Set validProfileIds = new HashSet<>(); + private final Set validProfileIds = ConcurrentHashMap.newKeySet(); @Inject public DefaultModelValidator() {} @@ -1496,7 +1497,7 @@ private boolean validateCoordinatesId( String id, String sourceHint, InputLocationTracker tracker) { - if (validCoordinatesIds.contains(id)) { + if (id != null && validCoordinatesIds.contains(id)) { return true; } if (!validateStringNotEmpty(prefix, fieldName, problems, severity, version, id, sourceHint, tracker)) { diff --git a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java index 932e4dfbaa52..c7c5a28be35b 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginDependenciesResolver.java @@ -134,8 +134,7 @@ public Artifact resolve(Plugin plugin, List repositories, Repo pluginArtifact = pluginArtifact.setProperties(props); } } catch (ArtifactDescriptorException e) { - throw new PluginResolutionException( - plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null); + throw new PluginResolutionException(plugin, e.getResult().getExceptions(), e); } try { @@ -143,8 +142,7 @@ public Artifact resolve(Plugin plugin, List repositories, Repo request.setTrace(trace); pluginArtifact = repoSystem.resolveArtifact(session, request).getArtifact(); } catch (ArtifactResolutionException e) { - throw new PluginResolutionException( - plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null); + throw new PluginResolutionException(plugin, e.getResult().getExceptions(), e); } return pluginArtifact; @@ -233,8 +231,7 @@ private DependencyResult resolveInternal( depRequest.setRoot(node); return repoSystem.resolveDependencies(session, depRequest); } catch (DependencyCollectionException e) { - throw new PluginResolutionException( - plugin, e.getResult().getExceptions(), logger.isDebugEnabled() ? e : null); + throw new PluginResolutionException(plugin, e.getResult().getExceptions(), e); } catch (DependencyResolutionException e) { List exceptions = Stream.concat( e.getResult().getCollectExceptions().stream(), @@ -242,7 +239,7 @@ private DependencyResult resolveInternal( .filter(r -> !r.isResolved()) .flatMap(r -> r.getExceptions().stream())) .collect(Collectors.toList()); - throw new PluginResolutionException(plugin, exceptions, logger.isDebugEnabled() ? e : null); + throw new PluginResolutionException(plugin, exceptions, e); } } } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java index 54c1762da94e..f814a3213615 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java @@ -160,9 +160,7 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request) result.setCollectionErrors(e.getResult().getExceptions()); throw new DependencyResolutionException( - result, - "Could not collect dependencies for project " + project.getId(), - logger.isDebugEnabled() ? e : null); + result, "Could not collect dependencies for project " + project.getId(), e); } depRequest.setRoot(node); @@ -192,9 +190,7 @@ public DependencyResolutionResult resolve(DependencyResolutionRequest request) process(result, e.getResult().getArtifactResults()); throw new DependencyResolutionException( - result, - "Could not resolve dependencies for project " + project.getId(), - logger.isDebugEnabled() ? e : null); + result, "Could not resolve dependencies for project " + project.getId(), e); } return result;