View | Details | Raw Unified | Return to bug 332838
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/ast/AssertStatement.java (-2 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 86-92 Link Here
86
		CompilerOptions compilerOptions = currentScope.compilerOptions();
86
		CompilerOptions compilerOptions = currentScope.compilerOptions();
87
		if (!compilerOptions.includeNullInfoFromAsserts) {
87
		if (!compilerOptions.includeNullInfoFromAsserts) {
88
			// keep just the initializations info, don't include assert's null info
88
			// keep just the initializations info, don't include assert's null info
89
			return flowInfo.mergedWith(assertInfo.nullInfoLessUnconditionalCopy());
89
			// merge initialization info's and then add back the null info from flowInfo to
90
			// make sure that the empty null info of assertInfo doesnt change flowInfo's null info.
91
			return ((flowInfo.nullInfoLessUnconditionalCopy()).mergedWith(assertInfo.nullInfoLessUnconditionalCopy())).addNullInfoFrom(flowInfo);
90
		}
92
		}
91
		return flowInfo.mergedWith(assertInfo.nullInfoLessUnconditionalCopy()).
93
		return flowInfo.mergedWith(assertInfo.nullInfoLessUnconditionalCopy()).
92
			addInitializationsFrom(assertWhenTrueInfo.discardInitializationInfo());
94
			addInitializationsFrom(assertWhenTrueInfo.discardInitializationInfo());
(-)src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java (+45 lines)
Lines 13832-13835 Link Here
13832
			"}"},
13832
			"}"},
13833
		"");
13833
		"");
13834
}
13834
}
13835
13836
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=332838
13837
// Null info of assert statements should not affect flow info
13838
// when CompilerOptions.OPTION_IncludeNullInfoFromAsserts is disabled.
13839
public void testBug332838() {
13840
	if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
13841
		Map compilerOptions = getCompilerOptions();
13842
		compilerOptions.put(CompilerOptions.OPTION_IncludeNullInfoFromAsserts, CompilerOptions.DISABLED);
13843
		this.runNegativeTest(
13844
			new String[] {
13845
				"Info.java",
13846
				"public class Info {\n" +
13847
				"	public void test(Info[] infos) {\n" +
13848
				"		for (final Info info : infos) {\n " +
13849
				"			if (info != null) {\n" +
13850
				"				assert info.checkSomething();\n" +
13851
				"		 		info.doSomething();\n" +	// no warning
13852
				"			}\n" +
13853
				"		 }\n" +
13854
				"		for (final Info info : infos) {\n " +
13855
				"			if (info == null) {\n" +
13856
				"				assert info.checkSomething();\n" +
13857
				"		 		info.doSomething();\n" +	// warn NPE, not pot. NPE
13858
				"			}\n" +
13859
				"		 }\n" +
13860
				"	}\n" +
13861
				"	void doSomething()  {}\n" +
13862
				"	boolean checkSomething() {return true;}\n" +
13863
				"}\n"},
13864
			"----------\n" + 
13865
			"1. ERROR in Info.java (at line 11)\n" + 
13866
			"	assert info.checkSomething();\n" + 
13867
			"	       ^^^^\n" + 
13868
			"Null pointer access: The variable info can only be null at this location\n" + 
13869
			"----------\n" + 
13870
			"2. ERROR in Info.java (at line 12)\n" + 
13871
			"	info.doSomething();\n" + 
13872
			"	^^^^\n" + 
13873
			"Null pointer access: The variable info can only be null at this location\n" + 
13874
			"----------\n",
13875
			null,
13876
			true,
13877
			compilerOptions);
13878
	}
13879
}
13835
}
13880
}

Return to bug 332838