Skip to content

Commit

Permalink
Fix concurrency issue in DefaultModelValidator (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored Oct 8, 2024
1 parent 954eae7 commit a6ecbde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -283,9 +284,9 @@ protected ActivationProperty.Builder transformActivationProperty_Value(
}
}

private final Set<String> validCoordinatesIds = new HashSet<>();
private final Set<String> validCoordinatesIds = ConcurrentHashMap.newKeySet();

private final Set<String> validProfileIds = new HashSet<>();
private final Set<String> validProfileIds = ConcurrentHashMap.newKeySet();

@Inject
public DefaultModelValidator() {}
Expand Down Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,15 @@ public Artifact resolve(Plugin plugin, List<RemoteRepository> 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 {
ArtifactRequest request = new ArtifactRequest(pluginArtifact, repositories, REPOSITORY_CONTEXT);
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;
Expand Down Expand Up @@ -233,16 +231,15 @@ 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<Exception> exceptions = Stream.concat(
e.getResult().getCollectExceptions().stream(),
e.getResult().getArtifactResults().stream()
.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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a6ecbde

Please sign in to comment.