### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java,v retrieving revision 1.56 diff -u -r1.56 LoopingFlowContext.java --- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 8 Mar 2011 16:46:01 -0000 1.56 +++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 11 Apr 2011 15:22:37 -0000 @@ -548,7 +548,10 @@ case CAN_ONLY_NULL | IN_ASSIGNMENT: case CAN_ONLY_NULL | IN_INSTANCEOF: if (flowInfo.isPotentiallyNonNull(local) - || flowInfo.isPotentiallyUnknown(local)) { + || flowInfo.isPotentiallyUnknown(local) + || flowInfo.isProtectedNonNull(local)) { + // if variable is not null, we are not interested in recording null reference for deferred checks. + // This is because CAN_ONLY_NULL means we're only interested in cases when variable can be null. return; } if (flowInfo.isDefinitelyNull(local)) { #P org.eclipse.jdt.core.tests.compiler Index: src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java,v retrieving revision 1.118 diff -u -r1.118 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 9 Mar 2011 13:57:50 -0000 1.118 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 11 Apr 2011 15:22:39 -0000 @@ -14530,4 +14530,52 @@ "Dead code\n" + "----------\n"); } +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=342300 +public void testBug342300() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runConformTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void initPattern(String p, Character escapeChar) {\n" + + " int len = p.length();\n" + + " for (int i = 0; i < len; i++) {\n" + + " char c = p.charAt(i);\n" + + " if (escapeChar != null && escapeChar == c) {\n" + // quiet + " c = p.charAt(++i);\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + ""); + } +} +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=342300 +// To make sure only the redundant null check is given and not a potential NPE +public void testBug342300b() throws Exception { + if (this.complianceLevel >= ClassFileConstants.JDK1_5) { + this.runNegativeTest( + new String[] { + "X.java", + "public class X {\n" + + " public static void initPattern(String p, Character escapeChar) {\n" + + " int len = p.length();\n" + + " for (int i = 0; i < len; i++) {\n" + + " char c = p.charAt(i);\n" + + " if (escapeChar != null && escapeChar != null) {\n" + // look here + " c = p.charAt(++i);\n" + + " }\n" + + " }\n" + + " }\n" + + "}", + }, + "----------\n" + + "1. ERROR in X.java (at line 6)\n" + + " if (escapeChar != null && escapeChar != null) {\n" + + " ^^^^^^^^^^\n" + + "Redundant null check: The variable escapeChar cannot be null at this location\n" + + "----------\n"); + } +} } \ No newline at end of file