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 189898 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]
sketch towards a possible solution
Bug_338234_sketch.patch (text/plain), 7.70 KB, created by
Stephan Herrmann
on 2011-02-27 13:39:13 EST
(
hide
)
Description:
sketch towards a possible solution
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2011-02-27 13:39:13 EST
Size:
7.70 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >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 27 Feb 2011 18:31:21 -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 >@@ -565,7 +565,7 @@ > */ > public void recordUsingNullReference(Scope scope, LocalVariableBinding local, > Expression reference, int checkType, FlowInfo flowInfo) { >- if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) != 0 || >+ if ((flowInfo.tagBits & (FlowInfo.UNREACHABLE|FlowInfo.UNREACHABLE_BY_NULLANALYSIS)) != 0 || > flowInfo.isDefinitelyUnknown(local)) { > return; > } >@@ -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 27 Feb 2011 18:31:21 -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 >@@ -24,6 +24,8 @@ > public final static int REACHABLE = 0; > public final static int UNREACHABLE = 1; > public final static int NULL_FLAG_MASK = 2; >+ public static final int UNREACHABLE_BY_NULLANALYSIS = 4; >+ > > public final static int UNKNOWN = 1; > public final static int NULL = 2; >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 27 Feb 2011 18:31:23 -0000 >@@ -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 27 Feb 2011 18:31:27 -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,27 @@ > "Dead code\n" + > "----------\n"); > } >+ >+public void testBug338234() { >+ 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. ERROR in X.java (at line 6)\n" + >+ " i++; \n" + >+ " ^\n" + >+ "The local variable i may not have been initialized\n" + >+ "----------\n"); >+} > public static Class testClass() { > return FlowAnalysisTest.class; > }
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