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 158695 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 patch for HEAD
patchAutoUnboxing.txt (text/plain), 26.95 KB, created by
Ayushman Jain
on 2010-02-10 06:51:54 EST
(
hide
)
Description:
updated patch for HEAD
Filename:
MIME Type:
Creator:
Ayushman Jain
Created:
2010-02-10 06:51:54 EST
Size:
26.95 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.32 >diff -u -r1.32 FinallyFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 5 Feb 2010 09:49:40 -0000 1.32 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FinallyFlowContext.java 10 Feb 2010 11:40:03 -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; > > /** >@@ -114,11 +115,19 @@ > 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; >+ } > if (!this.hideNullComparisonWarnings) { > 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; >+ } > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, expression); > } >@@ -130,6 +139,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: >@@ -214,12 +240,20 @@ > 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; >+ } > if (!this.hideNullComparisonWarnings) { > 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; >+ } > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >@@ -232,6 +266,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 : >@@ -273,12 +322,20 @@ > 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; >+ } > if (!this.hideNullComparisonWarnings) { > 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; >+ } > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >@@ -291,6 +348,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.63 >diff -u -r1.63 FlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 5 Feb 2010 09:49:40 -0000 1.63 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java 10 Feb 2010 11:40:13 -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; > > /** >@@ -569,12 +570,20 @@ > 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; >+ } > if (!this.hideNullComparisonWarnings) { > 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; >+ } > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >@@ -587,6 +596,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.47 >diff -u -r1.47 LoopingFlowContext.java >--- compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 5 Feb 2010 09:49:40 -0000 1.47 >+++ compiler/org/eclipse/jdt/internal/compiler/flow/LoopingFlowContext.java 10 Feb 2010 11:40:17 -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; > > /** >@@ -175,11 +176,19 @@ > 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; >+ } > if (!this.hideNullComparisonWarnings) { > 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; >+ } > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, expression); > } >@@ -191,7 +200,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)) { >@@ -238,11 +264,19 @@ > 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; >+ } > if (!this.hideNullComparisonWarnings) { > 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; >+ } > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, expression); > } >@@ -254,6 +288,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: >@@ -467,12 +518,20 @@ > 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; >+ } > if (!this.hideNullComparisonWarnings) { > 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; >+ } > if (!this.hideNullComparisonWarnings) { > scope.problemReporter().localVariableNullComparedToNonNull(local, reference); > } >@@ -485,6 +544,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; >+ } > } > // if the contention is inside assert statement, we want to avoid null warnings only in case of > // comparisons and not in case of assignment and instanceof >#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.86 >diff -u -r1.86 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 5 Feb 2010 09:49:35 -0000 1.86 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 10 Feb 2010 11:41:38 -0000 >@@ -11031,4 +11031,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
Flags:
Olivier_Thomann
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 253896
:
156203
|
156255
|
158215
| 158695