You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by GitBox <gi...@apache.org> on 2017/11/24 11:38:52 UTC

[GitHub] sdedic commented on a change in pull request #287: Fix 271823 False positive of "Non-null method returns null"

sdedic commented on a change in pull request #287: Fix 271823 False positive of "Non-null method returns null"
URL: https://github.com/apache/incubator-netbeans/pull/287#discussion_r152951231
 
 

 ##########
 File path: java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java
 ##########
 @@ -429,17 +430,37 @@ public static ErrorDescription returnNull(HintContext ctx) {
 
         TreePath method = ctx.getPath();
 
-        while (method != null && method.getLeaf().getKind() != Kind.METHOD && method.getLeaf().getKind() != Kind.CLASS) {
+        loop: while (method != null) {
+            switch (method.getLeaf().getKind()) {
+                case LAMBDA_EXPRESSION:
+                case METHOD:
+                // if we reach the enclosing class and still have not found
+                // the path to the method or lambda expression, then break.
+                case CLASS:
+                    break loop;
+            }
             method = method.getParentPath();
         }
 
-        if (method == null || method.getLeaf().getKind() != Kind.METHOD) return null;
+        if (method == null) return null;
+
+        CompilationInfo info = ctx.getInfo();
 
-        Element el = ctx.getInfo().getTrees().getElement(method);
+        Element el = null;
+        switch (method.getLeaf().getKind()) {
+            case LAMBDA_EXPRESSION:
+                TypeMirror functionalType = info.getTrees().getTypeMirror(method);
+                if (functionalType == null || functionalType.getKind() != TypeKind.DECLARED) return null;
 
 Review comment:
   instead of == null, use Utilities.isTypeValid(). It returns false for various non-null, but erroneous types (i.e. half-written source produces strange things)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services