Skip to content

Commit

Permalink
fix(qsync): NPE in "Add to project" panel action (#6967)
Browse files Browse the repository at this point in the history
A comment contains a warning that there should be at least two packages
found in order to provide user a choice. However in some cases there
is only a single package to add.

For this reason, we stop the lookup if it reaches project root,
but we don't add a package automatically, so a user can always reject
the change.

closes #6966
  • Loading branch information
Tomasz Pasternak authored Nov 6, 2024
1 parent 4b8c6d7 commit c63414c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ public ImmutableList<CandidatePackage> getCandidatePackages(
// - at least two paths with any packages in
// this is to offer the user some choice, and ensure we don't add paths with no packages in
// (which would cause the query to fail later on).
// However, sometimes there might be a case where there's only one valid package.
// in such a case, we return it, but we don't add it unconditionally.
do {
cancellationCheck.run();
packages = runQuery(forPath);
if (!packages.isEmpty()) {
candidates.add(new CandidatePackage(forPath, packages.size()));
}
forPath = forPath.getParent();
} while (candidates.size() < 2 && packages.size() < 2);
} while (candidates.size() < 2 && packages.size() < 2 && forPath != null);
return ImmutableList.copyOf(candidates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,12 @@ protected ImmutableList<CandidatePackage> compute(
}
});

if (candidatePackages.size() == 1) {
doAddToProjectView(Iterables.getOnlyElement(candidatePackages));
} else {
ListPopup popup =
JBPopupFactory.getInstance()
.createListPopup(
SelectPackagePopupStep.create(
candidatePackages, Performer.this::doAddToProjectView));
JBPopupFactory.getInstance()
.createListPopup(
SelectPackagePopupStep.create(
candidatePackages, Performer.this::doAddToProjectView));
popupPositioner.showInCorrectPosition(popup);
}
} catch (BuildException e) {
notify(
NotificationType.ERROR,
Expand Down

0 comments on commit c63414c

Please sign in to comment.