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

Collapse All | Expand All

(-)a/org.eclipse.jdt.annotation/src/org/eclipse/jdt/annotation/NonNull.java (-2 / +2 lines)
Lines 35-42 Link Here
35
 * <li>Nullness of the value can be statically determined, the entity is definitely bound from either of:
35
 * <li>Nullness of the value can be statically determined, the entity is definitely bound from either of:
36
 *     <ul><li>the value <code>null</code>, or</li>
36
 *     <ul><li>the value <code>null</code>, or</li>
37
 *         <li>an entity with a {@link Nullable @Nullable} type.</li></ul></li>
37
 *         <li>an entity with a {@link Nullable @Nullable} type.</li></ul></li>
38
 * <li>Nullness can not definitely be determined, because different code branches yield different results.</li>
38
 * <li>Nullness cannot definitely be determined, because different code branches yield different results.</li>
39
 * <li>Nullness can not be determined, because other program elements are involved for which
39
 * <li>Nullness cannot be determined, because other program elements are involved for which
40
 *     null annotations are lacking.</li>
40
 *     null annotations are lacking.</li>
41
 * </ol>
41
 * </ol>
42
 * </p>
42
 * </p>
(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullAnnotationTest.java (-1 / +31 lines)
Lines 52-58 Link Here
52
// Static initializer to specify tests subset using TESTS_* static variables
52
// Static initializer to specify tests subset using TESTS_* static variables
53
// All specified tests which do not belong to the class are skipped...
53
// All specified tests which do not belong to the class are skipped...
54
static {
54
static {
55
//		TESTS_NAMES = new String[] { "test_illegal_annotation_007" };
55
//		TESTS_NAMES = new String[] { "test_assignment_expression_1" };
56
//		TESTS_NUMBERS = new int[] { 561 };
56
//		TESTS_NUMBERS = new int[] { 561 };
57
//		TESTS_RANGE = new int[] { 1, 2049 };
57
//		TESTS_RANGE = new int[] { 1, 2049 };
58
}
58
}
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
public void test_assignment_expression_1() {
2478
	Map customOptions = getCompilerOptions();
2479
//	customOptions.put(CompilerOptions.OPTION_ReportPotentialNullSpecViolation, JavaCore.ERROR);
2480
	customOptions.put(JavaCore.COMPILER_NONNULL_IS_DEFAULT, JavaCore.ENABLED);
2481
	customOptions.put(JavaCore.COMPILER_PB_REDUNDANT_NULL_CHECK, JavaCore.ERROR);
2482
	runConformTestWithLibs(
2483
		new String[] {
2484
			"X.java",
2485
			"import org.eclipse.jdt.annotation.*;\n" +
2486
			"public class X {\n" +
2487
			"	@Nullable Object foo() {\n" +
2488
			"		Object o = null;\n" +
2489
			"		boolean keepLooking = true;\n" +
2490
			"		while(keepLooking) {\n" +
2491
			"			if ((o=getO()) != null) {\n" +
2492
			"				return o;\n" +
2493
			"			}\n" +
2494
			"		}\n" +
2495
			"		return null;\n" +
2496
			"	}\n" +
2497
			"\n" +
2498
			"	private @Nullable Object getO() {\n" +
2499
			"		return new Object();\n" +
2500
			"	}\n" +
2501
			"}\n",
2502
2503
		},
2504
		customOptions,
2505
		"");	
2506
}
2477
// a nonnull variable is dereferenced method of a nested type
2507
// a nonnull variable is dereferenced method of a nested type
2478
public void test_nesting_1() {
2508
public void test_nesting_1() {
2479
	Map customOptions = getCompilerOptions();
2509
	Map customOptions = getCompilerOptions();
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15JLS4Test.java (-5 / +7 lines)
Lines 7476-7482 Link Here
7476
    	assertTrue("Not assignement compatible", typeBinding.isAssignmentCompatible(typeBinding2));
7476
    	assertTrue("Not assignement compatible", typeBinding.isAssignmentCompatible(typeBinding2));
7477
    	assertTrue("Not assignement compatible", typeBinding.isAssignmentCompatible(collectionTypeBinding));
7477
    	assertTrue("Not assignement compatible", typeBinding.isAssignmentCompatible(collectionTypeBinding));
7478
	}
7478
	}
7479
7480
	/*
7479
	/*
7481
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=156352
7480
	 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=156352
7482
	 */
7481
	 */
Lines 7495-7504 Link Here
7495
				buffer.append(typeBinding.getAnnotations().length);
7494
				buffer.append(typeBinding.getAnnotations().length);
7496
				typeBinding= typeBinding.getSuperclass();
7495
				typeBinding= typeBinding.getSuperclass();
7497
			}
7496
			}
7498
			// initially, this test expected "000", but after https://bugs.eclipse.org/186342
7497
			// the right outcome would be "020", but depending on the strategy when exactly
7499
			// annotations are resolved more eagerly, which makes the annotations on Test2 show up,
7498
			// annotations are resolved the annotations on Test2 are (not) present when
7500
			// which is actually the right outcome.
7499
			// traversing the super-class chain.
7501
			assertEquals("Wrong number of annotations", "020", String.valueOf(buffer));
7500
			// The patch in https://bugs.eclipse.org/186342#c196 produced "020" but
7501
			// the previous behavior ("000") was restored in https://bugs.eclipse.org/365387
7502
			// (see the change in SourceTypeBinding.resolveTypesFor(..))
7503
			assertEquals("Wrong number of annotations", "000", String.valueOf(buffer));
7502
		}
7504
		}
7503
	}
7505
	}
7504
7506
(-)a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java (-4 / +7 lines)
Lines 7498-7507 Link Here
7498
				buffer.append(typeBinding.getAnnotations().length);
7498
				buffer.append(typeBinding.getAnnotations().length);
7499
				typeBinding= typeBinding.getSuperclass();
7499
				typeBinding= typeBinding.getSuperclass();
7500
			}
7500
			}
7501
			// initially, this test expected "000", but after https://bugs.eclipse.org/186342
7501
			// the right outcome would be "020", but depending on the strategy when exactly
7502
			// annotations are resolved more eagerly, which makes the annotations on Test2 show up,
7502
			// annotations are resolved the annotations on Test2 are (not) present when
7503
			// which is actually the right outcome.
7503
			// traversing the super-class chain.
7504
			assertEquals("Wrong number of annotations", "020", String.valueOf(buffer));
7504
			// The patch in https://bugs.eclipse.org/186342#c196 produced "020" but
7505
			// the previous behavior ("000") was restored in https://bugs.eclipse.org/365387
7506
			// (see the change in SourceTypeBinding.resolveTypesFor(..))
7507
			assertEquals("Wrong number of annotations", "000", String.valueOf(buffer));
7505
		}
7508
		}
7506
	}
7509
	}
7507
7510
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java (-2 / +2 lines)
Lines 119-125 Link Here
119
}
119
}
120
public void checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
120
public void checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
121
	super.checkNPE(scope, flowContext, flowInfo);
121
	super.checkNPE(scope, flowContext, flowInfo);
122
	if (nullStatus(flowInfo) == FlowInfo.POTENTIALLY_NULL)
122
	if ((nullStatus(flowInfo) & FlowInfo.POTENTIALLY_NULL) != 0)
123
		scope.problemReporter().messageSendPotentialNullReference(this.binding, this);
123
		scope.problemReporter().messageSendPotentialNullReference(this.binding, this);
124
}
124
}
125
/**
125
/**
Lines 281-287 Link Here
281
		if ((tagBits & TagBits.AnnotationNonNull) != 0)
281
		if ((tagBits & TagBits.AnnotationNonNull) != 0)
282
			return FlowInfo.NON_NULL;
282
			return FlowInfo.NON_NULL;
283
		if ((tagBits & TagBits.AnnotationNullable) != 0)
283
		if ((tagBits & TagBits.AnnotationNullable) != 0)
284
			return FlowInfo.POTENTIALLY_NULL;
284
			return FlowInfo.POTENTIALLY_NULL | FlowInfo.POTENTIALLY_NON_NULL;
285
	}
285
	}
286
	return FlowInfo.UNKNOWN;
286
	return FlowInfo.UNKNOWN;
287
}
287
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/flow/FlowContext.java (-2 / +3 lines)
Lines 564-572 Link Here
564
		while (size <= nullCount) size *= 2;
564
		while (size <= nullCount) size *= 2;
565
		this.expectedTypes = new TypeBinding[size];
565
		this.expectedTypes = new TypeBinding[size];
566
	}
566
	}
567
	else if (nullCount == this.expectedTypes.length) {
567
	else if (nullCount >= this.expectedTypes.length) {
568
		int oldLen = this.expectedTypes.length;
568
		System.arraycopy(this.expectedTypes, 0,
569
		System.arraycopy(this.expectedTypes, 0,
569
			this.expectedTypes = new TypeBinding[nullCount * 2], 0, nullCount);
570
			this.expectedTypes = new TypeBinding[nullCount * 2], 0, oldLen);
570
	}
571
	}
571
	this.expectedTypes[nullCount] = expectedType;
572
	this.expectedTypes[nullCount] = expectedType;
572
}
573
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java (+2 lines)
Lines 778-783 Link Here
778
			OPTION_NonNullIsDefault,
778
			OPTION_NonNullIsDefault,
779
			OPTION_ReportNullSpecViolation,
779
			OPTION_ReportNullSpecViolation,
780
			OPTION_ReportPotentialNullSpecViolation,
780
			OPTION_ReportPotentialNullSpecViolation,
781
			OPTION_ReportNullSpecInsufficientInfo,
781
			OPTION_ReportRedundantNullAnnotation
782
			OPTION_ReportRedundantNullAnnotation
782
		};
783
		};
783
		return result;
784
		return result;
Lines 1225-1230 Link Here
1225
		this.nullableAnnotationName = DEFAULT_NULLABLE_ANNOTATION_NAME;
1226
		this.nullableAnnotationName = DEFAULT_NULLABLE_ANNOTATION_NAME;
1226
		this.nonNullAnnotationName = DEFAULT_NONNULL_ANNOTATION_NAME;
1227
		this.nonNullAnnotationName = DEFAULT_NONNULL_ANNOTATION_NAME;
1227
		this.nonNullByDefaultAnnotationName = DEFAULT_NONNULLBYDEFAULT_ANNOTATION_NAME;
1228
		this.nonNullByDefaultAnnotationName = DEFAULT_NONNULLBYDEFAULT_ANNOTATION_NAME;
1229
		this.defaultNonNullness = 0;
1228
	}
1230
	}
1229
1231
1230
	public void set(Map optionsMap) {
1232
	public void set(Map optionsMap) {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java (-1 / +2 lines)
Lines 1597-1603 Link Here
1597
				typeParameters[i].binding = null;
1597
				typeParameters[i].binding = null;
1598
		return null;
1598
		return null;
1599
	}
1599
	}
1600
	createArgumentBindings(method);
1600
	if (this.scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled)
1601
		createArgumentBindings(method); // need annotations resolved already at this point
1601
	if (foundReturnTypeProblem)
1602
	if (foundReturnTypeProblem)
1602
		return method; // but its still unresolved with a null return type & is still connected to its method declaration
1603
		return method; // but its still unresolved with a null return type & is still connected to its method declaration
1603
1604
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Scanner.java (-2 / +2 lines)
Lines 547-557 Link Here
547
547
548
	if (this.lineEnds == null || this.linePtr == -1)
548
	if (this.lineEnds == null || this.linePtr == -1)
549
		return -1;
549
		return -1;
550
	if (lineNumber > this.linePtr + 2)
550
	if (lineNumber > this.lineEnds.length+1)
551
		return -1;
551
		return -1;
552
	if (lineNumber <= 0)
552
	if (lineNumber <= 0)
553
		return -1;
553
		return -1;
554
	if (lineNumber == this.linePtr + 2)
554
	if (lineNumber == this.lineEnds.length + 1)
555
		return this.eofPosition;
555
		return this.eofPosition;
556
	return this.lineEnds[lineNumber-1]; // next line start one character behind the lineEnd of the previous line
556
	return this.lineEnds[lineNumber-1]; // next line start one character behind the lineEnd of the previous line
557
}
557
}

Return to bug 365387