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

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


The following commit(s) were added to refs/heads/master by this push:
     new 39ba086  [NETBEANS-734] Caught exceptions are always non-null. (#525)
39ba086 is described below

commit 39ba08671ccd2860e3393851cc07e3eeccb0d2e9
Author: Jan Lahoda <lah...@gmail.com>
AuthorDate: Thu May 10 09:44:50 2018 +0200

    [NETBEANS-734] Caught exceptions are always non-null. (#525)
    
    * [NETBEANS-734] Caught exceptions are always non-null.
    
    * Adding braces as suggested during review.
    
    * Adding test ensuring assignments to exception parameters are reflected 
correctly.
---
 .../netbeans/modules/java/hints/bugs/NPECheck.java |  3 ++
 .../modules/java/hints/bugs/NPECheckTest.java      | 47 ++++++++++++++++++++++
 2 files changed, 50 insertions(+)

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 993e3e3..bc5b0e5 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 class NPECheck {
             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 ae14345..fc6717f 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 class NPECheckTest extends NbTestCase {
                 .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)

-- 
To stop receiving notification emails like this one, please contact
geert...@apache.org.

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