Skip to content

Commit

Permalink
Fix possible NPE during project building (#1759)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet authored Oct 1, 2024
1 parent 5207475 commit 04f3609
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -499,23 +499,30 @@ private List<ProjectBuildingResult> build(File pomFile, boolean recursive) {
List<ProjectBuildingResult> results = new ArrayList<>();
List<ModelBuilderResult> allModels = results(result).toList();
for (ModelBuilderResult r : allModels) {
File pom = r.getSource().getPath().toFile();
MavenProject project = projectIndex.get(r.getEffectiveModel().getId());
Path rootDirectory = rootLocator.findRoot(pom.getParentFile().toPath());
project.setRootDirectory(rootDirectory);
project.setFile(pom);
project.setExecutionRoot(pom.equals(pomFile));
initProject(project, r);
project.setCollectedProjects(results(r)
.filter(cr -> cr != r)
.map(cr -> projectIndex.get(cr.getEffectiveModel().getId()))
.collect(Collectors.toList()));

DependencyResolutionResult resolutionResult = null;
if (request.isResolveDependencies()) {
resolutionResult = resolveDependencies(project);
if (r.getEffectiveModel() != null) {
File pom = r.getSource().getPath().toFile();
MavenProject project =
projectIndex.get(r.getEffectiveModel().getId());
Path rootDirectory =
rootLocator.findRoot(pom.getParentFile().toPath());
project.setRootDirectory(rootDirectory);
project.setFile(pom);
project.setExecutionRoot(pom.equals(pomFile));
initProject(project, r);
project.setCollectedProjects(results(r)
.filter(cr -> cr != r)
.map(cr -> projectIndex.get(cr.getEffectiveModel().getId()))
.collect(Collectors.toList()));

DependencyResolutionResult resolutionResult = null;
if (request.isResolveDependencies()) {
resolutionResult = resolveDependencies(project);
}
results.add(
new DefaultProjectBuildingResult(project, convert(result.getProblems()), resolutionResult));
} else {
results.add(new DefaultProjectBuildingResult(null, convert(result.getProblems()), null));
}
results.add(new DefaultProjectBuildingResult(project, convert(result.getProblems()), resolutionResult));
}
return results;
}
Expand Down

0 comments on commit 04f3609

Please sign in to comment.