View | Details | Raw Unified | Return to bug 365387 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java (+85 lines)
Lines 2474-2479 Link Here
2474
		"Type mismatch: required \'@NonNull String\' but the provided value can be null\n" +
2474
		"Type mismatch: required \'@NonNull String\' but the provided value can be null\n" +
2475
		"----------\n");
2475
		"----------\n");
2476
}
2476
}
2477
// witness for an AIOOBE in FlowContext.recordExpectedType()
2478
public void test_message_send_in_control_structure_01() {
2479
	Map customOptions = getCompilerOptions();
2480
	customOptions.put(JavaCore.COMPILER_PB_NULL_SPECIFICATION_INSUFFICIENT_INFO, JavaCore.IGNORE);
2481
	customOptions.put(JavaCore.COMPILER_PB_POTENTIAL_NULL_REFERENCE, JavaCore.WARNING);
2482
	runNegativeTestWithLibs(
2483
		new String[] {
2484
			"p/Scope.java",
2485
			"package p;\n" +
2486
			"@org.eclipse.jdt.annotation.NonNullByDefault\n" +
2487
			"public abstract class Scope {\n" +
2488
			"	public ReferenceBinding findMemberType(char[] typeName, ReferenceBinding enclosingType) {\n" +
2489
			"		ReferenceBinding enclosingSourceType = enclosingSourceType();\n" +
2490
			"		PackageBinding currentPackage = getCurrentPackage();\n" +
2491
			"		CompilationUnitScope unitScope = compilationUnitScope();\n" +
2492
			"		ReferenceBinding memberType = enclosingType.getMemberType(typeName);\n" +
2493
			"		ReferenceBinding currentType = enclosingType;\n" +
2494
			"		ReferenceBinding[] interfacesToVisit = null;\n" +
2495
			"		while (true) {\n" +
2496
			"			ReferenceBinding[] itsInterfaces = currentType.superInterfaces();\n" +
2497
			"			if (itsInterfaces != null) {\n" +
2498
			"				if (interfacesToVisit == null) {\n" +
2499
			"					interfacesToVisit = itsInterfaces;\n" +
2500
			"				}\n" +
2501
			"			}\n" +
2502
			"			unitScope.recordReference(currentType, typeName);\n" +
2503
			"			\n" +
2504
			"			if ((memberType = currentType.getMemberType(typeName)) != null) {\n" +
2505
			"				if (enclosingSourceType == null\n" +
2506
			"					? memberType.canBeSeenBy(currentPackage)\n" +
2507
			"					: memberType.canBeSeenBy(enclosingType, enclosingSourceType)) {\n" +
2508
			"						return memberType;\n" +
2509
			"				}\n" +
2510
			"			}\n" +
2511
			"		}\n" +
2512
			"	}\n" +
2513
			"	private CompilationUnitScope compilationUnitScope() {\n" +
2514
			"		return compilationUnitScope();\n" +
2515
			"	}\n" +
2516
			"	private PackageBinding getCurrentPackage() {\n" +
2517
			"		return getCurrentPackage();\n" +
2518
			"	}\n" +
2519
			"	private ReferenceBinding enclosingSourceType() {\n" +
2520
			"		return enclosingSourceType();\n" +
2521
			"	}\n" +
2522
			"}\n",
2523
			"p/CompilationUnitScope.java",
2524
			"package p;\n" +
2525
			"@org.eclipse.jdt.annotation.NonNullByDefault\n" +
2526
			"public class CompilationUnitScope {\n" +
2527
			"    void recordReference(ReferenceBinding rb, char[] name) {}\n" +
2528
			"}\n",
2529
			"p/PackageBinding.java",
2530
			"package p;\n" +
2531
			"@org.eclipse.jdt.annotation.NonNullByDefault\n" +
2532
			"public class PackageBinding {\n" +
2533
			"}\n",
2534
			"p/ReferenceBinding.java",
2535
			"package p;\n" +
2536
			"@org.eclipse.jdt.annotation.NonNullByDefault\n" +
2537
			"public class ReferenceBinding {\n" +
2538
			"    ReferenceBinding getMemberType(char[] name) { return this; }\n" +
2539
			"    ReferenceBinding[] superInterfaces() { return new ReferenceBinding[0]; }\n" +
2540
			"    boolean canBeSeenBy(PackageBinding ob) { return true; }\n" +
2541
			"    boolean canBeSeenBy(ReferenceBinding rb, ReferenceBinding rb2) { return true; }\n" +
2542
			"}\n"
2543
		},
2544
		customOptions,
2545
		"----------\n" +
2546
		"1. ERROR in p\\Scope.java (at line 13)\n" +
2547
		"	if (itsInterfaces != null) {\n" +
2548
		"	    ^^^^^^^^^^^^^\n" +
2549
		"Redundant null check: The variable itsInterfaces cannot be null at this location\n" +
2550
		"----------\n" +
2551
		"2. ERROR in p\\Scope.java (at line 20)\n" +
2552
		"	if ((memberType = currentType.getMemberType(typeName)) != null) {\n" +
2553
		"	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
2554
		"Redundant null check: The variable memberType cannot be null at this location\n" +
2555
		"----------\n" +
2556
		"3. ERROR in p\\Scope.java (at line 21)\n" +
2557
		"	if (enclosingSourceType == null\n" +
2558
		"	    ^^^^^^^^^^^^^^^^^^^\n" +
2559
		"Null comparison always yields false: The variable enclosingSourceType cannot be null at this location\n" +
2560
		"----------\n");
2561
}
2477
public void test_assignment_expression_1() {
2562
public void test_assignment_expression_1() {
2478
	Map customOptions = getCompilerOptions();
2563
	Map customOptions = getCompilerOptions();
2479
//	customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR);
2564
//	customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR);

Return to bug 365387