Skip to content

Commit

Permalink
Merge pull request #3591 from lkishalmi/GH-3590
Browse files Browse the repository at this point in the history
[#3590] Prevent suspicious NPE forn Gradle SubProjectsNode
  • Loading branch information
neilcsmith-net committed Feb 15, 2022
2 parents b09ce42 + c1ebdea commit 5a1e8be
Showing 1 changed file with 15 additions and 5 deletions.
Expand Up @@ -26,8 +26,8 @@
import java.awt.event.ActionEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.swing.AbstractAction;
import javax.swing.Action;
Expand All @@ -48,6 +48,8 @@

import static org.netbeans.modules.gradle.nodes.Bundle.*;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.netbeans.api.project.ProjectUtils;
import org.netbeans.modules.gradle.api.GradleBaseProject;
import org.netbeans.modules.gradle.spi.Utils;
Expand All @@ -59,6 +61,8 @@
*/
public class SubProjectsNode extends AbstractNode {

private static final Logger LOG = Logger.getLogger(SubProjectsNode.class.getName());

@StaticResource
private static final String SP_BADGE
= "org/netbeans/modules/gradle/resources/gradle-large-badge.png";
Expand Down Expand Up @@ -122,13 +126,21 @@ private static class SubProjectsChildFactory extends ChildFactory<Project> {
protected boolean createKeys(final List<Project> projects) {

Set<Project> containedProjects = ProjectUtils.getContainedProjects(project, false);
projects.addAll(containedProjects);
if (containedProjects != null) {
projects.addAll(containedProjects);
} else {
LOG.log(Level.FINE, "No ProjectContainerProvider in the lookup of: {0}", project);
}
return true;
}

@Override
protected Node createNodeForKey(Project key) {
Set<Project> containedProjects = ProjectUtils.getContainedProjects(key, false);
if (containedProjects == null) {
containedProjects = Collections.emptySet();
LOG.log(Level.FINE, "No ProjectContainerProvider in the lookup of: {0}", project);
}
GradleBaseProject gbp = GradleBaseProject.get(project);
String prefix = (gbp != null && !gbp.isRoot() ? gbp.getPath() : "") + ':';
Children ch = containedProjects.isEmpty() ? Children.LEAF : Children.create(new SubProjectsChildFactory(key), true);
Expand Down Expand Up @@ -182,9 +194,7 @@ public String getDisplayName() {

@Override
public Action[] getActions(boolean b) {
ArrayList<Action> lst = new ArrayList<Action>();
lst.add(OpenProjectAction.SINGLETON);
return lst.toArray(new Action[lst.size()]);
return new Action[]{OpenProjectAction.SINGLETON};
}

@Override
Expand Down

0 comments on commit 5a1e8be

Please sign in to comment.