### 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 29 Jul 2010 17:57:28 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -60,6 +61,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 29 Jul 2010 17:57:28 -0000 @@ -7,7 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation - * Stephan Herrmann - Contribution for bug 236385 + * Stephan Herrmann - Contributions for + * bug 236385 - [compiler] Warn for potential programming problem if an object is created but not used + * bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -39,6 +41,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 29 Jul 2010 17:57:29 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -30,6 +31,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 29 Jul 2010 17:57:29 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -42,6 +43,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 29 Jul 2010 17:57:29 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Genady Beriozkin - added support for reporting assignment with no effect + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -37,6 +38,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 29 Jul 2010 17:57:31 -0000 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Nick Teryaev - fix for bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=40752) + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -47,9 +48,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 29 Jul 2010 17:57:31 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -57,6 +58,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 +75,14 @@ FlowInfo.UNREACHABLE) != 0) { this.continueLabel = null; } + if ((this.condition.implicitConversion & TypeIds.UNBOXING) != 0) { + initsOnCondition = flowInfo.unconditionalInits(). + addInitializationsFrom( + actionInfo.mergedWith(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 29 Jul 2010 17:57:32 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -76,6 +77,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 29 Jul 2010 17:57:32 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -92,6 +93,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 29 Jul 2010 17:57:33 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -57,6 +58,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 29 Jul 2010 17:57:33 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -40,6 +41,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 29 Jul 2010 17:57:34 -0000 @@ -8,6 +8,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Nick Teryaev - fix for bug (https://bugs.eclipse.org/bugs/show_bug.cgi?id=40752) + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -65,6 +66,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 29 Jul 2010 17:57:35 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -62,6 +63,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 29 Jul 2010 17:57:36 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -71,6 +72,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 29 Jul 2010 17:57:36 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -36,6 +37,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 29 Jul 2010 17:57:37 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -47,6 +48,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 29 Jul 2010 17:57:37 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. + * Copyright (c) 2000, 2010 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 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - Contribution for bug 319201 - [null] no warning when unboxing SingleNameReference causes NPE *******************************************************************************/ package org.eclipse.jdt.internal.compiler.ast; @@ -63,6 +64,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.96 diff -u -r1.96 NullReferenceTest.java --- src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 22 Jul 2010 14:15:48 -0000 1.96 +++ src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java 29 Jul 2010 17:57:53 -0000 @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Stephan Herrmann - [null] no warning when unboxing SingleNameReference causes NPE, see https://bugs.eclipse.org/319201 *******************************************************************************/ package org.eclipse.jdt.core.tests.compiler.regression; @@ -11662,6 +11663,290 @@ "----------\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 and/or continue in the body & empty body +public void testBug319201d() { + if (this.complianceLevel < ClassFileConstants.JDK1_5) + return; + Map customOptions = getCompilerOptions(); + customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.IGNORE); + 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 + " Boolean b5 = null;\n" + + " do {\n" + + " b5 = true;\n" + + " } while (b5);\n" + // don't complain + " Boolean b6 = null;\n" + + " do {\n" + + " b6 = true;\n" + + " continue;\n" + + " } while (b6); \n" + // don't complain + " Boolean b7 = null;\n" + + " Boolean b8 = null;\n" + + " do {\n" + + " if (cond) {\n" + + " b7 = true;\n" + + " continue;\n" + + " } else {\n" + + " b8 = true;\n" + + " }\n" + + " } while (b7);\n" + // complain here: after else branch b7 can still be 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" + + "3. ERROR in X.java (at line 42)\n" + + " } while (b7);\n" + + " ^^\n" + + "Potential null pointer access: The variable b7 may be null at this location\n" + + "----------\n", + null/*classLibraries*/, + true/*shouldFlushOutputDirectory*/, + customOptions); +} //https://bugs.eclipse.org/bugs/show_bug.cgi?id=320414 public void testBug320414() throws Exception { Map options = getCompilerOptions();