Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 190035 Details for
Bug 338234
[compiler] Missing warning for uninitialized variable in dead code
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
proposed fix v2.0 + tests
patch338234_v21.txt (text/plain), 19.80 KB, created by
Ayushman Jain
on 2011-03-01 08:37:46 EST
(
hide
)
Description:
proposed fix v2.0 + tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2011-03-01 08:37:46 EST
Size:
19.80 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java,v >retrieving revision 1.35 >diff -u -r1.35 FinallyFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 25 Feb 2010 15:27:00 -0000 1.35 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 1 Mar 2011 13:32:49 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -229,14 +229,14 @@ > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } else if (checkType == (CAN_ONLY_NULL_NON_NULL | IN_COMPARISON_NULL)) { > if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } > return; >@@ -252,7 +252,7 @@ > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_COMPARISON_NON_NULL: >@@ -264,7 +264,7 @@ > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_ASSIGNMENT: >@@ -314,14 +314,14 @@ > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } else { > if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } > return; >@@ -342,7 +342,7 @@ > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_COMPARISON_NON_NULL: >@@ -354,7 +354,7 @@ > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_ASSIGNMENT: >Index: compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java,v >retrieving revision 1.68 >diff -u -r1.68 FlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 1 Sep 2010 15:49:57 -0000 1.68 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 1 Mar 2011 13:32:49 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -578,14 +578,14 @@ > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } else { > if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } > return; >@@ -609,7 +609,7 @@ > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_COMPARISON_NON_NULL: >@@ -621,7 +621,7 @@ > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_ASSIGNMENT: >Index: compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java,v >retrieving revision 1.45 >diff -u -r1.45 FlowInfo.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java 16 Dec 2010 13:02:30 -0000 1.45 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowInfo.java 1 Mar 2011 13:32:49 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2010 IBM Corporation and others. >+ * Copyright (c) 2000, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -22,8 +22,23 @@ > > public int tagBits; // REACHABLE by default > public final static int REACHABLE = 0; >- public final static int UNREACHABLE = 1; >+ /* unreachable code as defined in the language spec >+ * eg. while (true); >+ * i++; --> unreachable code >+ */ >+ public final static int UNREACHABLE_OR_DEAD = 1; > public final static int NULL_FLAG_MASK = 2; >+ /* unreachable code as inferred by null analysis >+ * eg. str = null; >+ * if (str != null) { >+ * // dead code >+ * } >+ */ >+ public final static int UNREACHABLE_BY_NULLANALYSIS = 4; >+ /* >+ * code unreachable in any fashion >+ */ >+ public final static int UNREACHABLE = UNREACHABLE_OR_DEAD | UNREACHABLE_BY_NULLANALYSIS; > > public final static int UNKNOWN = 1; > public final static int NULL = 2; >@@ -456,9 +471,9 @@ > } > > /** >- * Return REACHABLE if this flow info is reachable, UNREACHABLE >+ * Return REACHABLE if this flow info is reachable, UNREACHABLE|UNREACHABLE_BY_NULLANALYSIS > * else. >- * @return REACHABLE if this flow info is reachable, UNREACHABLE >+ * @return REACHABLE if this flow info is reachable, UNREACHABLE|UNREACHABLE_BY_NULLANALYSIS > * else > */ > public int reachMode() { >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.52 >diff -u -r1.52 LoopingFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 16 Feb 2011 18:57:48 -0000 1.52 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 1 Mar 2011 13:32:49 -0000 >@@ -493,14 +493,14 @@ > scope.problemReporter().localVariableRedundantCheckOnNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } else { > if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { > scope.problemReporter().localVariableNonNullComparedToNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } > } else if (flowInfo.isDefinitelyNull(local)) { >@@ -509,14 +509,14 @@ > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } else { > if ((this.tagBits & FlowContext.HIDE_NULL_COMPARISON_WARNING) == 0) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > } > } else if (this.upstreamNullFlowInfo.isDefinitelyNonNull(local) && !flowInfo.isPotentiallyNull(local) && !flowInfo.isPotentiallyUnknown(local)) { >@@ -554,7 +554,7 @@ > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_COMPARISON_NON_NULL: >@@ -566,7 +566,7 @@ > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } > if (!flowInfo.isMarkedAsNullOrNonNullInAssertExpression(local)) { >- flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); >+ flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE_BY_NULLANALYSIS); > } > return; > case FlowContext.IN_ASSIGNMENT: >Index: compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java,v >retrieving revision 1.72 >diff -u -r1.72 UnconditionalFlowInfo.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 19 Jan 2011 05:29:54 -0000 1.72 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/UnconditionalFlowInfo.java 1 Mar 2011 13:32:49 -0000 >@@ -731,7 +731,7 @@ > final public boolean isDefinitelyAssigned(FieldBinding field) { > // Mirrored in CodeStream.isDefinitelyAssigned(..) > // do not want to complain in unreachable code >- if ((this.tagBits & UNREACHABLE) != 0) { >+ if ((this.tagBits & UNREACHABLE_OR_DEAD) != 0) { > return true; > } > return isDefinitelyAssigned(field.id); >@@ -739,7 +739,7 @@ > > final public boolean isDefinitelyAssigned(LocalVariableBinding local) { > // do not want to complain in unreachable code if local declared in reachable code >- if ((this.tagBits & UNREACHABLE) != 0 && (local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0) { >+ if ((this.tagBits & UNREACHABLE_OR_DEAD) != 0 && (local.declaration.bits & ASTNode.IsLocalDeclarationReachable) != 0) { > return true; > } > return isDefinitelyAssigned(local.id + this.maxFieldCount); >@@ -1563,6 +1563,17 @@ > na1, na2, na3, na4, > nb1, nb2, nb3, nb4, > b1, b2, b3, b4; >+ if ((otherInits.tagBits & FlowInfo.UNREACHABLE_BY_NULLANALYSIS) != 0) { >+ otherHasNulls = false; // skip merging, otherInits is unreachable by null analysis >+ } else { >+ if ((this.tagBits & FlowInfo.UNREACHABLE_BY_NULLANALYSIS) != 0) { // directly copy if this is unreachable by null analysis >+ this.nullBit1 = otherInits.nullBit1; >+ this.nullBit2 = otherInits.nullBit2; >+ this.nullBit3 = otherInits.nullBit3; >+ this.nullBit4 = otherInits.nullBit4; >+ thisHadNulls = false; >+ thisHasNulls = otherHasNulls; >+ } else > if (thisHadNulls) { > if (otherHasNulls) { > this.nullBit1 = (a2 = this.nullBit2) & (a3 = this.nullBit3) >@@ -1636,6 +1647,7 @@ > this.nullBit3 != 0 || > this.nullBit4 != 0; > } >+ } > > // treating extra storage > if (this.extra != null || otherInits.extra != null) { >@@ -1858,6 +1870,8 @@ > } > if (reachMode == REACHABLE ) { > this.tagBits &= ~UNREACHABLE; >+ } else if (reachMode == UNREACHABLE_BY_NULLANALYSIS) { >+ this.tagBits |= UNREACHABLE_BY_NULLANALYSIS; // don't interfere with definite assignment analysis > } else { > if ((this.tagBits & UNREACHABLE) == 0) { > // reset optional inits when becoming unreachable >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java,v >retrieving revision 1.46 >diff -u -r1.46 FlowAnalysisTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 1 Sep 2010 15:49:30 -0000 1.46 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/FlowAnalysisTest.java 1 Mar 2011 13:32:52 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2010 IBM Corporation and others. >+ * Copyright (c) 2005, 2011 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -29,7 +29,9 @@ > public class FlowAnalysisTest extends AbstractRegressionTest { > static { > // TESTS_NUMBERS = new int[] { 69 }; >+// TESTS_NAMES = new String[] { "testBug338234" }; > } >+ > public FlowAnalysisTest(String name) { > super(name); > } >@@ -2246,6 +2248,92 @@ > "Dead code\n" + > "----------\n"); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 >+// Warn uninitialized variable in deadcode if deadcode has been inferred >+// by null analysis >+public void testBug338234a() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " int i;\n" + >+ " String str = null;\n" + >+ " if (str != null)\n" + >+ " i++; \n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. WARNING in X.java (at line 6)\n" + >+ " i++; \n" + >+ " ^^^\n" + >+ "Dead code\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 6)\n" + >+ " i++; \n" + >+ " ^\n" + >+ "The local variable i may not have been initialized\n" + >+ "----------\n"); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 >+// Don't warn uninitialized variable in deadcode if deadcode has not been inferred >+// by null analysis >+public void testBug338234b() { >+ this.runConformTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public static void main(String[] args) {\n" + >+ " int i;\n" + >+ " l: {\n" + >+ " if(false)\n" + >+ " break l;\n" + >+ " return;\n" + >+ " }\n" + >+ " i++; \n" + >+ " }\n" + >+ "}\n" >+ }, >+ ""); >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 >+// Warn uninitialized field in deadcode if deadcode has been inferred >+// by null analysis >+public void testBug338234c() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public final int field1;\n" + >+ " {\n" + >+ " int i;\n" + >+ " String str = null;\n" + >+ " if(str != null)\n" + >+ " i = field1;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ "----------\n" + >+ "1. ERROR in X.java (at line 1)\n" + >+ " public class X {\n" + >+ " ^\n" + >+ "The blank final field field1 may not have been initialized\n" + >+ "----------\n" + >+ "2. WARNING in X.java (at line 7)\n" + >+ " i = field1;\n" + >+ " ^^^^^^^^^^\n" + >+ "Dead code\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 7)\n" + >+ " i = field1;\n" + >+ " ^^^^^^\n" + >+ "The blank final field field1 may not have been initialized\n" + >+ "----------\n"); >+} > public static Class testClass() { > return FlowAnalysisTest.class; > } >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.113 >diff -u -r1.113 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 27 Feb 2011 21:42:50 -0000 1.113 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 1 Mar 2011 13:32:52 -0000 >@@ -14060,4 +14060,28 @@ > }, > ""); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=338234 >+public void testBug338234() { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " static int foo() {\n" + >+ " Object o = null;\n" + >+ " int i = 0;\n" + >+ " label: {\n" + >+ " if (o == null)\n" + >+ " break label;\n" + >+ " i++;" + >+ " }\n" + >+ " if (i != 0) {\n" + >+ " System.out.println(i);\n" + >+ " }\n" + >+ " return 0;\n" + >+ " }\n" + >+ "}\n" >+ }, >+ ""); >+} > } >\ No newline at end of file
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 338234
:
189898
|
189936
|
190035
|
190073
|
190298
|
190355