dtrebbien 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_r153026637
 
 

 ##########
 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:
   Done

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to