geertjanw closed pull request #525: [NETBEANS-734] Caught exceptions are always 
non-null.
URL: https://github.com/apache/incubator-netbeans/pull/525
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java 
b/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java
index 993e3e351..bc5b0e516 100644
--- a/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java
+++ b/java.hints/src/org/netbeans/modules/java/hints/bugs/NPECheck.java
@@ -706,6 +706,9 @@ public State visitVariable(VariableTree node, Void p) {
             mergeHypotheticalVariable2State(orig);
             
             if (e != null) {
+                if (e.getKind() == ElementKind.EXCEPTION_PARAMETER) {
+                    r = NOT_NULL;
+                }
                 variable2State.put((VariableElement) e, r);
                 TreePath pp = getCurrentPath().getParentPath();
                 if (pp != null) {
diff --git 
a/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/NPECheckTest.java
 
b/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/NPECheckTest.java
index ae143455f..fc6717f56 100644
--- 
a/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/NPECheckTest.java
+++ 
b/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/NPECheckTest.java
@@ -1696,6 +1696,53 @@ public void testNETBEANS407d() throws Exception {
                 .assertWarnings("3:44-3:52:verifier:Possibly Dereferencing 
null");
     }
     
+    public void testExceptionIsNonNullNETBEANS734a() throws Exception {
+        HintTest.create()
+                .input("package test;\n" +
+                       "public class Test {\n" +
+                       "  public void test(Object o) {\n" +
+                       "    try {\n" +
+                       "    } catch (Exception e) {\n" +
+                       "        if (e instanceof RuntimeException) {}\n" +
+                       "        System.err.println(e.toString());\n" +
+                       "    }\n" +
+                       "  }\n" +
+                       "}")
+                .run(NPECheck.class)
+                .assertWarnings();
+    }
+
+    public void testExceptionIsNonNullNETBEANS734b() throws Exception {
+        HintTest.create()
+                .input("package test;\n" +
+                       "public class Test {\n" +
+                       "  public void test(Object o) {\n" +
+                       "    try {\n" +
+                       "    } catch (Exception e) {\n" +
+                       "        if (e != null) {}\n" +
+                       "    }\n" +
+                       "  }\n" +
+                       "}")
+                .run(NPECheck.class)
+                .assertWarnings("5:12-5:21:verifier:ERR_NotNull");
+    }
+
+    public void testExceptionIsNonNullNETBEANS734c() throws Exception {
+        HintTest.create()
+                .input("package test;\n" +
+                       "public class Test {\n" +
+                       "  public void test(Object o) {\n" +
+                       "    try {\n" +
+                       "    } catch (Exception e) {\n" +
+                       "        e = null;\n" +
+                       "        System.err.println(e.toString());\n" +
+                       "    }\n" +
+                       "  }\n" +
+                       "}")
+                .run(NPECheck.class)
+                .assertWarnings("6:29-6:37:verifier:DN");
+    }
+
     private void performAnalysisTest(String fileName, String code, String... 
golden) throws Exception {
         HintTest.create()
                 .input(fileName, code)


 

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@netbeans.apache.org
For additional commands, e-mail: notifications-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