diff options
| author | Stephan Herrmann | 2013-02-22 22:41:51 +0000 |
|---|---|---|
| committer | Jayaprakash Arthanareeswaran | 2013-04-03 09:02:19 +0000 |
| commit | 1878129a89601d3b46b2a79a651fda5de1f409e2 (patch) | |
| tree | af8944ec2d377e2066d9d58b5e330261ad55cc10 | |
| parent | 03f81049867c7013f420abfd6b051cc95502966c (diff) | |
| download | eclipse.jdt.core-1878129a89601d3b46b2a79a651fda5de1f409e2.tar.gz eclipse.jdt.core-1878129a89601d3b46b2a79a651fda5de1f409e2.tar.xz eclipse.jdt.core-1878129a89601d3b46b2a79a651fda5de1f409e2.zip | |
Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in
outer catch of nested try
2 files changed, 80 insertions, 2 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java index 6465eb952e..20f8574523 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java @@ -28,6 +28,7 @@ * bug 331649 - [compiler][null] consider null annotations for fields * bug 382789 - [compiler][null] warn when syntactically-nonnull expression is compared against null * bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement + * bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -16300,4 +16301,80 @@ public void testBug401088a() { }, "1java.lang.Exception"); } +// Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try +public void test401092() { + runConformTest( + new String[] { + "X.java", + "import java.util.Date;\n" + + "\n" + + "public class X {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static Date createDate() throws Exception {\n" + + " occasionallyThrowException();\n" + + " return new Date();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Date d = null;\n" + + " try {\n" + + " d = createDate();\n" + + " System.out.println(d.toString());\n" + + " try {\n" + + " occasionallyThrowException();\n" + + " }\n" + + " catch (Exception exc) {\n" + + " }\n" + + " }\n" + + " catch (Exception exc) {\n" + + " if (d != null) // should not warn in this line\n" + + " System.out.println(d.toString());\n" + + " }\n" + + " }\n" + + "}\n" + }); +} +// Bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try +public void test401092a() { + runConformTest( + new String[] { + "X.java", + "import java.util.Date;\n" + + "\n" + + "public class X {\n" + + "\n" + + " private static void occasionallyThrowException() throws Exception {\n" + + " throw new Exception();\n" + + " }\n" + + "\n" + + " private static Date createDate() throws Exception {\n" + + " occasionallyThrowException();\n" + + " return new Date();\n" + + " }\n" + + "\n" + + " public static void main(String s[]) {\n" + + " Date d = null;\n" + + " try {\n" + + " d = createDate();\n" + + " System.out.println(d.toString());\n" + + " try {\n" + + " occasionallyThrowException();\n" + + " }\n" + + " catch (Exception exc) {\n" + + " }\n" + + " finally { System.out.println(1); }\n" + + " }\n" + + " catch (Exception exc) {\n" + + " if (d != null) // should not warn in this line\n" + + " System.out.println(d.toString());\n" + + " }\n" + + " finally { System.out.println(2); }\n" + + " }\n" + + "}\n" + }); +} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java index 96987f6ca0..5d937f8e14 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/TryStatement.java @@ -16,6 +16,7 @@ * bug 345305 - [compiler][null] Compiler misidentifies a case of "variable can only be null" * bug 388996 - [compiler][resource] Incorrect 'potential resource leak' * bug 401088 - [compiler][null] Wrong warning "Redundant null check" inside nested try statement + * bug 401092 - [compiler][null] Wrong warning "Redundant null check" in outer catch of nested try *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -249,7 +250,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl // chain up null info registry if (flowContext.initsOnFinally != null) { - flowContext.initsOnFinally.addNullInfoFrom(handlingContext.initsOnFinally); + flowContext.mergeFinallyNullInfo(handlingContext.initsOnFinally); } return tryInfo; @@ -428,7 +429,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl // chain up null info registry if (flowContext.initsOnFinally != null) { - flowContext.initsOnFinally.addNullInfoFrom(handlingContext.initsOnFinally); + flowContext.mergeFinallyNullInfo(handlingContext.initsOnFinally); } this.naturalExitMergeInitStateIndex = |
