This is an automated email from the ASF dual-hosted git repository.

neilcsmith pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new cc3101fdbf Fix possible NPU in Java Editor UnusedDetector
     new ca91d1962c Merge pull request #4006 from 
lkishalmi/fix-npe-in-unuseddetector
cc3101fdbf is described below

commit cc3101fdbf746cded30f8cc0e7bd54f24424f865
Author: Laszlo Kishalmi <laszlo.kisha...@gmail.com>
AuthorDate: Tue Apr 19 14:27:36 2022 -0700

    Fix possible NPU in Java Editor UnusedDetector
---
 .../java/editor/base/semantic/UnusedDetector.java  | 59 ++++++++++++----------
 1 file changed, 31 insertions(+), 28 deletions(-)

diff --git 
a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java
 
b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java
index 35cfe1295d..3e19f4f321 100644
--- 
a/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java
+++ 
b/java/java.editor.base/src/org/netbeans/modules/java/editor/base/semantic/UnusedDetector.java
@@ -319,39 +319,42 @@ public class UnusedDetector {
         }
         ElementHandle eh = ElementHandle.create(el);
         Set<FileObject> res = 
info.getClasspathInfo().getClassIndex().getResources(ElementHandle.create(typeElement),
 searchKinds, scope);
-        for (FileObject fo : res) {
-            if (fo != info.getFileObject()) {
-                JavaSource js = JavaSource.forFileObject(fo);
-                if (js == null) {
-                    return false;
-                }
-                AtomicBoolean found = new AtomicBoolean();
-                try {
-                    js.runUserActionTask(cc -> {
-                        cc.toPhase(JavaSource.Phase.RESOLVED);
-                        new TreePathScanner<Void, Element>() {
-                            @Override
-                            public Void scan(Tree tree, Element p) {
-                                if (!found.get() && tree != null) {
-                                    Element element = 
cc.getTrees().getElement(new TreePath(getCurrentPath(), tree));
-                                    if (element != null && 
eh.signatureEquals(element)) {
-                                        found.set(true);
+        if (res != null) {
+            for (FileObject fo : res) {
+                if (fo != info.getFileObject()) {
+                    JavaSource js = JavaSource.forFileObject(fo);
+                    if (js == null) {
+                        return false;
+                    }
+                    AtomicBoolean found = new AtomicBoolean();
+                    try {
+                        js.runUserActionTask(cc -> {
+                            cc.toPhase(JavaSource.Phase.RESOLVED);
+                            new TreePathScanner<Void, Element>() {
+                                @Override
+                                public Void scan(Tree tree, Element p) {
+                                    if (!found.get() && tree != null) {
+                                        Element element = 
cc.getTrees().getElement(new TreePath(getCurrentPath(), tree));
+                                        if (element != null && 
eh.signatureEquals(element)) {
+                                            found.set(true);
+                                        }
+                                        super.scan(tree, p);
                                     }
-                                    super.scan(tree, p);
+                                    return null;
                                 }
-                                return null;
-                            }
-                        }.scan(new TreePath(cc.getCompilationUnit()), el);
-                    }, true);
-                } catch (IOException ex) {
-                    Exceptions.printStackTrace(ex);
-                }
-                if (found.get()) {
-                    return false;
+                            }.scan(new TreePath(cc.getCompilationUnit()), el);
+                        }, true);
+                    } catch (IOException ex) {
+                        Exceptions.printStackTrace(ex);
+                    }
+                    if (found.get()) {
+                        return false;
+                    }
                 }
             }
+            return true;
         }
-        return true;
+        return false;
     }
 
     private enum UseTypes {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to