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 158215 Details for
Bug 253896
[compiler][null] wrong "Null comparison always yields false" problem for auto-unboxing
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
updated fix + regression tests
patchAutoUnboxing.txt (text/plain), 26.53 KB, created by
Ayushman Jain
on 2010-02-04 14:16:01 EST
(
hide
)
Description:
updated fix + regression tests
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2010-02-04 14:16:01 EST
Size:
26.53 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.31 >diff -u -r1.31 FinallyFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 21 Jan 2010 16:48:36 -0000 1.31 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 4 Feb 2010 19:10:33 -0000 >@@ -17,6 +17,7 @@ > import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; > import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; > import org.eclipse.jdt.internal.compiler.lookup.Scope; >+import org.eclipse.jdt.internal.compiler.lookup.TypeIds; > import org.eclipse.jdt.internal.compiler.lookup.VariableBinding; > > /** >@@ -110,9 +111,17 @@ > if (flowInfo.isDefinitelyNull(local)) { > switch(this.nullCheckTypes[i] & CONTEXT_MASK) { > case FlowContext.IN_COMPARISON_NULL: >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, expression); >+ continue; >+ } > scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); > continue; > case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, expression); >+ continue; >+ } > scope.problemReporter().localVariableNullComparedToNonNull(local, expression); > continue; > case FlowContext.IN_ASSIGNMENT: >@@ -122,6 +131,23 @@ > scope.problemReporter().localVariableNullInstanceof(local, expression); > continue; > } >+ } else if (flowInfo.isPotentiallyNull(local)) { >+ switch(this.nullCheckTypes[i] & CONTEXT_MASK) { >+ case FlowContext.IN_COMPARISON_NULL: >+ this.nullReferences[i] = null; >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, expression); >+ continue; >+ } >+ break; >+ case FlowContext.IN_COMPARISON_NON_NULL: >+ this.nullReferences[i] = null; >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, expression); >+ continue; >+ } >+ break; >+ } > } > break; > case MAY_NULL: >@@ -202,10 +228,18 @@ > if (flowInfo.canOnlyBeNull(local)) { > switch(checkType & CONTEXT_MASK) { > case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); > return; > case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); > return; >@@ -216,6 +250,21 @@ > scope.problemReporter().localVariableNullInstanceof(local, reference); > return; > } >+ } else if (flowInfo.isPotentiallyNull(local)) { >+ switch(checkType & CONTEXT_MASK) { >+ case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ } > } > break; > case MAY_NULL : >@@ -253,10 +302,18 @@ > if (flowInfo.isDefinitelyNull(local)) { > switch(checkType & CONTEXT_MASK) { > case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); > return; > case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); > return; >@@ -267,6 +324,21 @@ > scope.problemReporter().localVariableNullInstanceof(local, reference); > return; > } >+ } else if (flowInfo.isPotentiallyNull(local)) { >+ switch(checkType & CONTEXT_MASK) { >+ case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ } > } > break; > case MAY_NULL : >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.62 >diff -u -r1.62 FlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 21 Jan 2010 16:48:36 -0000 1.62 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 4 Feb 2010 19:10:33 -0000 >@@ -27,6 +27,7 @@ > import org.eclipse.jdt.internal.compiler.lookup.Scope; > import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; > import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; >+import org.eclipse.jdt.internal.compiler.lookup.TypeIds; > import org.eclipse.jdt.internal.compiler.lookup.VariableBinding; > > /** >@@ -561,10 +562,18 @@ > if (flowInfo.isDefinitelyNull(local)) { > switch(checkType & CONTEXT_MASK) { > case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); > return; > case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); > return; >@@ -575,6 +584,21 @@ > scope.problemReporter().localVariableNullInstanceof(local, reference); > return; > } >+ } else if (flowInfo.isPotentiallyNull(local)) { >+ switch(checkType & CONTEXT_MASK) { >+ case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ } > } else if (flowInfo.cannotBeDefinitelyNullOrNonNull(local)) { > return; > } >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.46 >diff -u -r1.46 LoopingFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 21 Jan 2010 16:48:36 -0000 1.46 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 4 Feb 2010 19:10:33 -0000 >@@ -18,6 +18,7 @@ > import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; > import org.eclipse.jdt.internal.compiler.lookup.LocalVariableBinding; > import org.eclipse.jdt.internal.compiler.lookup.Scope; >+import org.eclipse.jdt.internal.compiler.lookup.TypeIds; > import org.eclipse.jdt.internal.compiler.lookup.VariableBinding; > > /** >@@ -163,9 +164,17 @@ > this.nullReferences[i] = null; > switch(this.nullCheckTypes[i] & CONTEXT_MASK) { > case FlowContext.IN_COMPARISON_NULL: >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, expression); >+ continue; >+ } > scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); > continue; > case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, expression); >+ continue; >+ } > scope.problemReporter().localVariableNullComparedToNonNull(local, expression); > continue; > case FlowContext.IN_ASSIGNMENT: >@@ -175,7 +184,24 @@ > scope.problemReporter().localVariableNullInstanceof(local, expression); > continue; > } >- } >+ } else if (flowInfo.isPotentiallyNull(local)) { >+ switch(this.nullCheckTypes[i] & CONTEXT_MASK) { >+ case FlowContext.IN_COMPARISON_NULL: >+ this.nullReferences[i] = null; >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, expression); >+ continue; >+ } >+ break; >+ case FlowContext.IN_COMPARISON_NON_NULL: >+ this.nullReferences[i] = null; >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, expression); >+ continue; >+ } >+ break; >+ } >+ } > break; > case MAY_NULL: > if (flowInfo.isDefinitelyNull(local)) { >@@ -218,9 +244,17 @@ > this.nullReferences[i] = null; > switch(this.nullCheckTypes[i] & CONTEXT_MASK) { > case FlowContext.IN_COMPARISON_NULL: >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, expression); >+ continue; >+ } > scope.problemReporter().localVariableRedundantCheckOnNull(local, expression); > continue; > case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, expression); >+ continue; >+ } > scope.problemReporter().localVariableNullComparedToNonNull(local, expression); > continue; > case FlowContext.IN_ASSIGNMENT: >@@ -230,6 +264,23 @@ > scope.problemReporter().localVariableNullInstanceof(local, expression); > continue; > } >+ } else if (flowInfo.isPotentiallyNull(local)) { >+ switch(this.nullCheckTypes[i] & CONTEXT_MASK) { >+ case FlowContext.IN_COMPARISON_NULL: >+ this.nullReferences[i] = null; >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, expression); >+ continue; >+ } >+ break; >+ case FlowContext.IN_COMPARISON_NON_NULL: >+ this.nullReferences[i] = null; >+ if (((this.nullCheckTypes[i] & CHECK_MASK) == CAN_ONLY_NULL) && (expression.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, expression); >+ continue; >+ } >+ break; >+ } > } > break; > case MAY_NULL: >@@ -431,10 +482,18 @@ > if (flowInfo.isDefinitelyNull(local)) { > switch(checkType & CONTEXT_MASK) { > case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableRedundantCheckOnNull(local, reference); > flowInfo.initsWhenFalse().setReachMode(FlowInfo.UNREACHABLE); > return; > case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariableNullReference(local, reference); >+ return; >+ } > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > flowInfo.initsWhenTrue().setReachMode(FlowInfo.UNREACHABLE); > return; >@@ -445,6 +504,21 @@ > scope.problemReporter().localVariableNullInstanceof(local, reference); > return; > } >+ } else if (flowInfo.isPotentiallyNull(local)) { >+ switch(checkType & CONTEXT_MASK) { >+ case FlowContext.IN_COMPARISON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ case FlowContext.IN_COMPARISON_NON_NULL: >+ if (((checkType & CHECK_MASK) == CAN_ONLY_NULL) && (reference.implicitConversion & TypeIds.UNBOXING) != 0) { // check for auto-unboxing first and report appropriate warning >+ scope.problemReporter().localVariablePotentialNullReference(local, reference); >+ return; >+ } >+ break; >+ } > } > recordNullReference(local, reference, checkType); > return; >#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.85 >diff -u -r1.85 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 21 Jan 2010 17:06:52 -0000 1.85 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 4 Feb 2010 19:10:42 -0000 >@@ -10753,4 +10753,222 @@ > "Potential null pointer access: The variable bar may be null at this location\n" + > "----------\n"); > } >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 >+// Test whether Null pointer access warnings are being reported correctly when auto-unboxing >+public void testBug253896a() { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Integer f1 = null;\n" + >+ " if(f1 == 1)\n" + >+ " System.out.println(\"f1 is 1\");\n" + >+ " Integer f2 = null;\n" + >+ " int abc = (f2 != 1)? 1 : 0;\n" + >+ " Float f3 = null;\n" + >+ " if(f3 == null)\n" + >+ " System.out.println(\"f3 is null\");\n" + >+ " Byte f4 = null;\n" + >+ " if(f4 != null)\n" + >+ " System.out.println(\"f4 is not null\");\n" + >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " if(f1 == 1)\n" + >+ " ^^\n" + >+ "Null pointer access: The variable f1 can only be null at this location\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 7)\n" + >+ " int abc = (f2 != 1)? 1 : 0;\n" + >+ " ^^\n" + >+ "Null pointer access: The variable f2 can only be null at this location\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 9)\n" + >+ " if(f3 == null)\n" + >+ " ^^\n" + >+ "Redundant null check: The variable f3 can only be null at this location\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 12)\n" + >+ " if(f4 != null)\n" + >+ " ^^\n" + >+ "Null comparison always yields false: The variable f4 can only be null at this location\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 13)\n" + >+ " System.out.println(\"f4 is not null\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Dead code\n" + >+ "----------\n"); >+ } >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 >+// To test whether null pointer access and potential null pointer access warnings are correctly reported when auto-unboxing >+public void testBug253896b() { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo(Integer i1, Integer i2) {\n" + >+ " if(i1 == null && i2 == null){\n" + >+ " if(i1 == 1)\n" + >+ " System.out.println(i1);}\n" + //i1 is definitely null here >+ " else {\n" + >+ " if(i1 == 0) {}\n" + //i1 may be null here. >+ " }\n" + >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " if(i1 == 1)\n" + >+ " ^^\n" + >+ "Null pointer access: The variable i1 can only be null at this location\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 7)\n" + >+ " if(i1 == 0) {}\n" + >+ " ^^\n" + >+ "Potential null pointer access: The variable i1 may be null at this location\n" + >+ "----------\n"); >+ } >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 >+// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside loops >+public void testBug253896c() { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Integer a = null;\n" + >+ " Integer outer2 = null;\n" + >+ " while (true) {\n" + >+ " Integer f1 = null;\n" + >+ " if(f1 == 1)\n" + >+ " System.out.println(\"f1 is 1\");\n" + >+ " Integer f2 = null;\n" + >+ " int abc = (f2 != 1)? 1 : 0;\n" + >+ " Float f3 = null;\n" + >+ " if(f3 == null)\n" + >+ " System.out.println(\"f3 is null\");\n" + >+ " Byte f4 = null;\n" + >+ " if(f4 != null)\n" + >+ " System.out.println(\"f4 is not null\");\n" + >+ " if(a == 1) {}\n" + // warn null reference in deferred check case >+ " if(outer2 == 1) {}\n" + // warn potential null reference in deferred check case >+ " outer2 = 1;\n" + >+ " }\n" + >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 7)\n" + >+ " if(f1 == 1)\n" + >+ " ^^\n" + >+ "Null pointer access: The variable f1 can only be null at this location\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 10)\n" + >+ " int abc = (f2 != 1)? 1 : 0;\n" + >+ " ^^\n" + >+ "Null pointer access: The variable f2 can only be null at this location\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 12)\n" + >+ " if(f3 == null)\n" + >+ " ^^\n" + >+ "Redundant null check: The variable f3 can only be null at this location\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 15)\n" + >+ " if(f4 != null)\n" + >+ " ^^\n" + >+ "Null comparison always yields false: The variable f4 can only be null at this location\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 16)\n" + >+ " System.out.println(\"f4 is not null\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Dead code\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 17)\n" + >+ " if(a == 1) {}\n" + >+ " ^\n" + >+ "Null pointer access: The variable a can only be null at this location\n" + >+ "----------\n" + >+ "7. ERROR in X.java (at line 18)\n" + >+ " if(outer2 == 1) {}\n" + >+ " ^^^^^^\n" + >+ "Potential null pointer access: The variable outer2 may be null at this location\n" + >+ "----------\n"); >+ } >+} >+ >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896 >+// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside finally contexts >+public void testBug253896d() { >+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) { >+ this.runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo(Integer param) {\n" + >+ " Integer outer = null;\n" + >+ " if (param == null) {}\n" + //tainting param >+ " try {}\n" + >+ " finally {\n" + >+ " Integer f1 = null;\n" + >+ " if(f1 == 1)\n" + >+ " System.out.println(\"f1 is 1\");\n" + >+ " Integer f2 = null;\n" + >+ " int abc = (f2 != 1)? 1 : 0;\n" + >+ " Float f3 = null;\n" + >+ " if(f3 == null)\n" + >+ " System.out.println(\"f3 is null\");\n" + >+ " Byte f4 = null;\n" + >+ " if(f4 != null)\n" + >+ " System.out.println(\"f4 is not null\");\n" + >+ " if(outer == 1) {}\n" + // warn null reference in deferred check case >+ " if(param == 1) {}\n" + >+ " }\n" + >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 8)\n" + >+ " if(f1 == 1)\n" + >+ " ^^\n" + >+ "Null pointer access: The variable f1 can only be null at this location\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 11)\n" + >+ " int abc = (f2 != 1)? 1 : 0;\n" + >+ " ^^\n" + >+ "Null pointer access: The variable f2 can only be null at this location\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 13)\n" + >+ " if(f3 == null)\n" + >+ " ^^\n" + >+ "Redundant null check: The variable f3 can only be null at this location\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 16)\n" + >+ " if(f4 != null)\n" + >+ " ^^\n" + >+ "Null comparison always yields false: The variable f4 can only be null at this location\n" + >+ "----------\n" + >+ "5. WARNING in X.java (at line 17)\n" + >+ " System.out.println(\"f4 is not null\");\n" + >+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + >+ "Dead code\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 18)\n" + >+ " if(outer == 1) {}\n" + >+ " ^^^^^\n" + >+ "Null pointer access: The variable outer can only be null at this location\n" + >+ "----------\n" + >+ "7. ERROR in X.java (at line 19)\n" + >+ " if(param == 1) {}\n" + >+ " ^^^^^\n" + >+ "Potential null pointer access: The variable param may be null at this location\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 253896
:
156203
|
156255
|
158215
|
158695