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 174950 Details for
Bug 319201
[null] no warning when unboxing SingleNameReference causes NPE
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
improved patch
bug_319201_v2.patch (text/plain), 26.66 KB, created by
Stephan Herrmann
on 2010-07-22 05:49:18 EDT
(
hide
)
Description:
improved patch
Filename:
MIME Type:
Creator:
Stephan Herrmann
Created:
2010-07-22 05:49:18 EDT
Size:
26.66 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java,v >retrieving revision 1.44 >diff -u -r1.44 AND_AND_Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java 22 Jul 2009 17:56:52 -0000 1.44 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/AND_AND_Expression.java 22 Jul 2010 09:43:00 -0000 >@@ -60,6 +60,12 @@ > } > } > rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo); >+ if ((this.left.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.left.checkNPE(currentScope, flowContext, flowInfo); >+ } >+ if ((this.right.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.right.checkNPE(currentScope, flowContext, flowInfo); >+ } > FlowInfo mergedInfo = FlowInfo.conditional( > rightInfo.safeInitsWhenTrue(), > leftInfo.initsWhenFalse().unconditionalInits().mergedWith( >Index: compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java,v >retrieving revision 1.83 >diff -u -r1.83 AllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 13 Jan 2010 15:13:49 -0000 1.83 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java 22 Jul 2010 09:43:01 -0000 >@@ -39,6 +39,9 @@ > this.arguments[i] > .analyseCode(currentScope, flowContext, flowInfo) > .unconditionalInits(); >+ if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.arguments[i].checkNPE(currentScope, flowContext, flowInfo); >+ } > } > } > // record some dependency information for exception types >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java,v >retrieving revision 1.43 >diff -u -r1.43 ArrayAllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java 27 Jun 2008 16:03:56 -0000 1.43 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ArrayAllocationExpression.java 22 Jul 2010 09:43:01 -0000 >@@ -30,6 +30,9 @@ > Expression dim; > if ((dim = this.dimensions[i]) != null) { > flowInfo = dim.analyseCode(currentScope, flowContext, flowInfo); >+ if ((dim.implicitConversion & TypeIds.UNBOXING) != 0) { >+ dim.checkNPE(currentScope, flowContext, flowInfo); >+ } > } > } > if (this.initializer != null) { >Index: compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java,v >retrieving revision 1.62 >diff -u -r1.62 AssertStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java 25 Feb 2010 15:27:01 -0000 1.62 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java 22 Jul 2010 09:43:01 -0000 >@@ -42,6 +42,9 @@ > this.preAssertInitStateIndex = currentScope.methodScope().recordInitializationStates(flowInfo); > > Constant cst = this.assertExpression.optimizedBooleanConstant(); >+ if ((this.assertExpression.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.assertExpression.checkNPE(currentScope, flowContext, flowInfo); >+ } > boolean isOptimizedTrueAssertion = cst != Constant.NotAConstant && cst.booleanValue() == true; > boolean isOptimizedFalseAssertion = cst != Constant.NotAConstant && cst.booleanValue() == false; > >Index: compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java,v >retrieving revision 1.89 >diff -u -r1.89 Assignment.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 14 Jul 2010 10:37:15 -0000 1.89 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/Assignment.java 22 Jul 2010 09:43:02 -0000 >@@ -37,6 +37,9 @@ > // a field reference, a blank final field reference, a field of an enclosing instance or > // just a local variable. > LocalVariableBinding local = this.lhs.localVariableBinding(); >+ if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.expression.checkNPE(currentScope, flowContext, flowInfo); >+ } > int nullStatus = this.expression.nullStatus(flowInfo); > if (local != null && (local.type.tagBits & TagBits.IsBaseType) == 0) { > if (nullStatus == FlowInfo.NULL) { >Index: compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java,v >retrieving revision 1.135 >diff -u -r1.135 CastExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 22 Jul 2010 04:25:45 -0000 1.135 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/CastExpression.java 22 Jul 2010 09:43:03 -0000 >@@ -47,9 +47,13 @@ > } > > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { >- return this.expression >+ FlowInfo result = this.expression > .analyseCode(currentScope, flowContext, flowInfo) > .unconditionalInits(); >+ if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.expression.checkNPE(currentScope, flowContext, flowInfo); >+ } >+ return result; > } > > /** >Index: compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java,v >retrieving revision 1.60 >diff -u -r1.60 DoStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java 19 Jun 2009 16:11:34 -0000 1.60 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/DoStatement.java 22 Jul 2010 09:43:03 -0000 >@@ -57,6 +57,8 @@ > > int previousMode = flowInfo.reachMode(); > >+ FlowInfo initsOnCondition = flowInfo; >+ > UnconditionalFlowInfo actionInfo = flowInfo.nullInfoLessUnconditionalCopy(); > // we need to collect the contribution to nulls of the coming paths through the > // loop, be they falling through normally or branched to break, continue labels >@@ -72,6 +74,16 @@ > FlowInfo.UNREACHABLE) != 0) { > this.continueLabel = null; > } >+ if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) { >+ if ((actionInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { >+ initsOnCondition = flowInfo.unconditionalCopy(). >+ addPotentialInitializationsFrom(actionInfo). >+ addInitializationsFrom(loopingContext.initsOnContinue); >+ } >+ } >+ } >+ if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.condition.checkNPE(currentScope, flowContext, initsOnCondition); > } > /* Reset reach mode, to address following scenario. > * final blank; >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java,v >retrieving revision 1.73 >diff -u -r1.73 ExplicitConstructorCall.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java 25 Nov 2009 04:56:02 -0000 1.73 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ExplicitConstructorCall.java 22 Jul 2010 09:43:04 -0000 >@@ -76,6 +76,9 @@ > this.arguments[i] > .analyseCode(currentScope, flowContext, flowInfo) > .unconditionalInits(); >+ if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.arguments[i].checkNPE(currentScope, flowContext, flowInfo); >+ } > } > } > >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java,v >retrieving revision 1.67 >diff -u -r1.67 ForStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java 7 Mar 2009 01:08:07 -0000 1.67 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ForStatement.java 22 Jul 2010 09:43:05 -0000 >@@ -92,6 +92,9 @@ > new LoopingFlowContext(flowContext, flowInfo, this, null, > null, this.scope)), > condInfo); >+ if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.condition.checkNPE(currentScope, flowContext, flowInfo); >+ } > } > } > >Index: compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java,v >retrieving revision 1.68 >diff -u -r1.68 IfStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 21 Jul 2010 07:08:54 -0000 1.68 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/IfStatement.java 22 Jul 2010 09:43:05 -0000 >@@ -57,6 +57,9 @@ > int initialComplaintLevel = (flowInfo.reachMode() & FlowInfo.UNREACHABLE) != 0 ? Statement.COMPLAINED_FAKE_REACHABLE : Statement.NOT_COMPLAINED; > > Constant cst = this.condition.optimizedBooleanConstant(); >+ if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.condition.checkNPE(currentScope, flowContext, flowInfo); >+ } > boolean isConditionOptimizedTrue = cst != Constant.NotAConstant && cst.booleanValue() == true; > boolean isConditionOptimizedFalse = cst != Constant.NotAConstant && cst.booleanValue() == false; > >Index: compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java,v >retrieving revision 1.71 >diff -u -r1.71 LocalDeclaration.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 23 Oct 2009 15:15:26 -0000 1.71 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/LocalDeclaration.java 22 Jul 2010 09:43:06 -0000 >@@ -40,6 +40,9 @@ > if (this.initialization == null) { > return flowInfo; > } >+ if ((this.initialization.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.initialization.checkNPE(currentScope, flowContext, flowInfo); >+ } > int nullStatus = this.initialization.nullStatus(flowInfo); > flowInfo = > this.initialization >Index: compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java,v >retrieving revision 1.147 >diff -u -r1.147 MessageSend.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 22 Jul 2010 04:25:45 -0000 1.147 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java 22 Jul 2010 09:43:07 -0000 >@@ -65,6 +65,9 @@ > if (this.arguments != null) { > int length = this.arguments.length; > for (int i = 0; i < length; i++) { >+ if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.arguments[i].checkNPE(currentScope, flowContext, flowInfo); >+ } > flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo).unconditionalInits(); > } > } >Index: compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java,v >retrieving revision 1.44 >diff -u -r1.44 OR_OR_Expression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java 21 Jan 2010 17:06:49 -0000 1.44 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/OR_OR_Expression.java 22 Jul 2010 09:43:07 -0000 >@@ -62,6 +62,12 @@ > } > } > rightInfo = this.right.analyseCode(currentScope, flowContext, rightInfo); >+ if ((this.left.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.left.checkNPE(currentScope, flowContext, flowInfo); >+ } >+ if ((this.right.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.right.checkNPE(currentScope, flowContext, flowInfo); >+ } > // The definitely null variables in right info when true should not be missed out while merging > // https://bugs.eclipse.org/bugs/show_bug.cgi?id=299900 > FlowInfo leftInfoWhenTrueForMerging = leftInfo.initsWhenTrue().unconditionalCopy().addPotentialInitializationsFrom(rightInfo.unconditionalInitsWithoutSideEffect()); >Index: compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java,v >retrieving revision 1.100 >diff -u -r1.100 QualifiedAllocationExpression.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 23 Jun 2010 06:52:46 -0000 1.100 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java 22 Jul 2010 09:43:08 -0000 >@@ -71,6 +71,9 @@ > if (this.arguments != null) { > for (int i = 0, count = this.arguments.length; i < count; i++) { > flowInfo = this.arguments[i].analyseCode(currentScope, flowContext, flowInfo); >+ if ((this.arguments[i].implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.arguments[i].checkNPE(currentScope, flowContext, flowInfo); >+ } > } > } > >Index: compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java,v >retrieving revision 1.67 >diff -u -r1.67 ReturnStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 7 Mar 2009 00:58:57 -0000 1.67 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/ReturnStatement.java 22 Jul 2010 09:43:08 -0000 >@@ -36,6 +36,9 @@ > > if (this.expression != null) { > flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo); >+ if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.expression.checkNPE(currentScope, flowContext, flowInfo); >+ } > } > this.initStateIndex = > currentScope.methodScope().recordInitializationStates(flowInfo); >Index: compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java,v >retrieving revision 1.78 >diff -u -r1.78 SwitchStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java 18 Jun 2010 16:28:33 -0000 1.78 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java 22 Jul 2010 09:43:09 -0000 >@@ -47,6 +47,9 @@ > public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) { > try { > flowInfo = this.expression.analyseCode(currentScope, flowContext, flowInfo); >+ if ((this.expression.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.expression.checkNPE(currentScope, flowContext, flowInfo); >+ } > SwitchFlowContext switchContext = > new SwitchFlowContext(flowContext, this, (this.breakLabel = new BranchLabel())); > >Index: compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java,v >retrieving revision 1.64 >diff -u -r1.64 WhileStatement.java >--- compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java 7 Mar 2009 01:08:07 -0000 1.64 >+++ compiler/org/eclipse/jdt/internal/compiler/ast/WhileStatement.java 22 Jul 2010 09:43:10 -0000 >@@ -63,6 +63,9 @@ > new LoopingFlowContext(flowContext, flowInfo, this, null, > null, currentScope)), > condInfo); >+ if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) { >+ this.condition.checkNPE(currentScope, flowContext, flowInfo); >+ } > > LoopingFlowContext loopingContext; > FlowInfo actionInfo; >#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.95 >diff -u -r1.95 NullReferenceTest.java >--- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 16 Mar 2010 14:36:08 -0000 1.95 >+++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 22 Jul 2010 09:43:27 -0000 >@@ -11662,4 +11662,260 @@ > "----------\n", > JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); > } >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 >+// unboxing raises an NPE >+// LocalDeclaration >+public void testBug319201() { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) >+ return; >+ runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Integer i = null;\n" + >+ " int j = i;\n" + // should warn >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " int j = i;\n" + >+ " ^\n" + >+ "Null pointer access: The variable i can only be null at this location\n" + >+ "----------\n", >+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 >+// unboxing could raise an NPE >+// Assignment >+public void testBug319201a() { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) >+ return; >+ runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo(Integer i) {\n" + >+ " if (i == null) {};\n" + >+ " int j;\n" + >+ " j = i;\n" + // should warn >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 5)\n" + >+ " j = i;\n" + >+ " ^\n" + >+ "Potential null pointer access: The variable i may be null at this location\n" + >+ "----------\n", >+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 >+// unboxing raises an NPE >+// MessageSend >+public void testBug319201b() { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) >+ return; >+ runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo() {\n" + >+ " Boolean bo = null;;\n" + >+ " bar(bo);\n" + // should warn >+ " }\n" + >+ " void bar(boolean b) {}\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " bar(bo);\n" + >+ " ^^\n" + >+ "Null pointer access: The variable bo can only be null at this location\n" + >+ "----------\n", >+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 >+// unboxing raises an NPE >+// Node types covered (in this order): >+// ExplicitConstructorCall >+// AllocationExpression >+// AND_AND_Expression >+// OR_OR_Expression >+// ArrayAllocationExpression >+// ForStatement >+// DoStatement >+// IfStatement >+// QualifiedAllocationExpression >+// SwitchStatement >+// WhileStatement >+// CastExpression >+// AssertStatement >+// ReturnStatement >+public void testBug319201c() { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) >+ return; >+ runNegativeTest( >+ new String[] { >+ "X.java", >+ "class Y { public Y(boolean b1, boolean b2) {} }\n" + >+ "public class X extends Y {\n" + >+ " public X(boolean b, Boolean b2) {\n" + >+ " super(b2 == null, b2);\n" + >+ " }\n" + >+ " class Z {\n" + >+ " public Z(boolean b) {}\n" + >+ " }\n" + >+ " boolean fB = (Boolean)null;\n" + >+ " public boolean foo(boolean inB) {\n" + >+ " Boolean b1 = null;\n" + >+ " X x = new X(b1, null);\n" + >+ " Boolean b2 = null;\n" + >+ " boolean dontcare = b2 && inB;\n" + >+ " Boolean b3 = null;\n" + >+ " dontcare = inB || b3;\n" + >+ " Integer dims = null;\n" + >+ " char[] cs = new char[dims];\n" + >+ " Boolean b5 = null;\n" + >+ " do {\n" + >+ " Boolean b4 = null;\n" + >+ " for (int i=0;b4; i++);\n" + >+ " } while (b5);\n" + >+ " Boolean b6 = null;\n" + >+ " if (b6) { }\n" + >+ " Boolean b7 = null;\n" + >+ " Z z = this.new Z(b7);\n" + >+ " Integer sel = null;\n" + >+ " switch(sel) {\n" + >+ " case 1: break;\n" + >+ " default: break;\n" + >+ " }\n" + >+ " Boolean b8 = null;\n" + >+ " while (b8) {}\n" + >+ " Boolean b9 = null;\n" + >+ " dontcare = (boolean)b9;\n" + >+ " Boolean b10 = null;\n" + >+ " assert b10 : \"shouldn't happen, but will\";\n" + >+ " Boolean b11 = null;\n" + >+ " return b11;\n" + >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 4)\n" + >+ " super(b2 == null, b2);\n" + >+ " ^^\n" + >+ "Potential null pointer access: The variable b2 may be null at this location\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 12)\n" + >+ " X x = new X(b1, null);\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b1 can only be null at this location\n" + >+ "----------\n" + >+ "3. ERROR in X.java (at line 14)\n" + >+ " boolean dontcare = b2 && inB;\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b2 can only be null at this location\n" + >+ "----------\n" + >+ "4. ERROR in X.java (at line 16)\n" + >+ " dontcare = inB || b3;\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b3 can only be null at this location\n" + >+ "----------\n" + >+ "5. ERROR in X.java (at line 18)\n" + >+ " char[] cs = new char[dims];\n" + >+ " ^^^^\n" + >+ "Null pointer access: The variable dims can only be null at this location\n" + >+ "----------\n" + >+ "6. ERROR in X.java (at line 22)\n" + >+ " for (int i=0;b4; i++);\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b4 can only be null at this location\n" + >+ "----------\n" + >+ "7. ERROR in X.java (at line 23)\n" + >+ " } while (b5);\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b5 can only be null at this location\n" + >+ "----------\n" + >+ "8. ERROR in X.java (at line 25)\n" + >+ " if (b6) { }\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b6 can only be null at this location\n" + >+ "----------\n" + >+ "9. ERROR in X.java (at line 27)\n" + >+ " Z z = this.new Z(b7);\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b7 can only be null at this location\n" + >+ "----------\n" + >+ "10. ERROR in X.java (at line 29)\n" + >+ " switch(sel) {\n" + >+ " ^^^\n" + >+ "Null pointer access: The variable sel can only be null at this location\n" + >+ "----------\n" + >+ "11. ERROR in X.java (at line 34)\n" + >+ " while (b8) {}\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b8 can only be null at this location\n" + >+ "----------\n" + >+ "12. ERROR in X.java (at line 36)\n" + >+ " dontcare = (boolean)b9;\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b9 can only be null at this location\n" + >+ "----------\n" + >+ "13. ERROR in X.java (at line 38)\n" + >+ " assert b10 : \"shouldn\'t happen, but will\";\n" + >+ " ^^^\n" + >+ "Null pointer access: The variable b10 can only be null at this location\n" + >+ "----------\n" + >+ "14. ERROR in X.java (at line 40)\n" + >+ " return b11;\n" + >+ " ^^^\n" + >+ "Null pointer access: The variable b11 can only be null at this location\n" + >+ "----------\n", >+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); >+} >+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319201 >+// unboxing raises an NPE >+// DoStatement, variants with assignement in the body & empty body >+public void testBug319201d() { >+ if (this.complianceLevel < ClassFileConstants.JDK1_5) >+ return; >+ runNegativeTest( >+ new String[] { >+ "X.java", >+ "public class X {\n" + >+ " public void foo(boolean cond, boolean cond2) {\n" + >+ " Boolean b = null;\n" + >+ " do {\n" + >+ " b = false;\n" + >+ " if (cond) continue;\n" + // shouldn't make a difference >+ " } while (b);\n" + // don't complain, loop body has already assigned b >+ " Boolean b2 = null;\n" + >+ " do {\n" + >+ " if (cond) continue;\n" + >+ " b2 = false;\n" + >+ " } while (b2);\n" + // complain here: potentially null >+ " Boolean b3 = null;\n" + >+ " do {\n" + >+ " } while (b3);\n" + // complain here: definitely null >+ " Boolean b4 = null;\n" + >+ " do {\n" + >+ " if (cond) {\n" + >+ " b4 = true;\n" + >+ " if (cond2) continue;\n" + >+ " }\n" + >+ " b4 = false;\n" + >+ " } while (b4);\n" + // don't complain here: definitely non-null >+ " }\n" + >+ "}"}, >+ "----------\n" + >+ "1. ERROR in X.java (at line 12)\n" + >+ " } while (b2);\n" + >+ " ^^\n" + >+ "Potential null pointer access: The variable b2 may be null at this location\n" + >+ "----------\n" + >+ "2. ERROR in X.java (at line 15)\n" + >+ " } while (b3);\n" + >+ " ^^\n" + >+ "Null pointer access: The variable b3 can only be null at this location\n" + >+ "----------\n", >+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError); >+} > } >\ 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 319201
:
173727
|
174412
|
174950
|
174994
|
175518