Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 434899
Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java (+45 lines)
Lines 3777-3782 Link Here
3777
			getCompilerOptions(),
3777
			getCompilerOptions(),
3778
			"");
3778
			"");
3779
	}
3779
	}
3780
	// https://bugs.eclipse.org/434899
3781
	public void testTypeVariable6() {
3782
		runNegativeTestWithLibs(
3783
			new String[] {
3784
				"Assert.java",
3785
				"import org.eclipse.jdt.annotation.*;\n" +
3786
				"public class Assert {\n" + 
3787
				"	public static void caller() {\n" + 
3788
				"		assertNotNull(\"not null\");	// Compiler error\n" + 
3789
				"		assertNotNull(null);		// Compiler error\n" + 
3790
				"	}\n" + 
3791
				"	private static @NonNull <T> T assertNotNull(@Nullable T object) {\n" + 
3792
				"		return object; // this IS bogus\n" + 
3793
				"	}\n" + 
3794
				"}\n"
3795
			},
3796
			getCompilerOptions(),
3797
			"----------\n" + 
3798
			"1. ERROR in Assert.java (at line 8)\n" + 
3799
			"	return object; // this IS bogus\n" + 
3800
			"	       ^^^^^^\n" + 
3801
			"Null type mismatch (type annotations): required \'@NonNull T\' but this expression has type \'@Nullable T\'\n" + 
3802
			"----------\n");
3803
	}
3804
	// https://bugs.eclipse.org/434899 - variant which has always worked
3805
	public void testTypeVariable6a() {
3806
		runConformTestWithLibs(
3807
			new String[] {
3808
				"Assert.java",
3809
				"import org.eclipse.jdt.annotation.*;\n" +
3810
				"public class Assert {\n" + 
3811
				"	public static Object caller() {\n" + 
3812
				"		@NonNull Object result = assertNotNull(\"not null\");\n" + 
3813
				"		result = assertNotNull(null);\n" +
3814
				"		return result;\n" + 
3815
				"	}\n" + 
3816
				"	private static @NonNull <T> T assertNotNull(@Nullable T object) {\n" +
3817
				"		if (object == null) throw new NullPointerException();\n" + 
3818
				"		return object;\n" + 
3819
				"	}\n" + 
3820
				"}\n"
3821
			},
3822
			getCompilerOptions(),
3823
			"");
3824
	}
3780
	public void testSE7AnnotationCopy() { // we were dropping annotations here, but null analysis worked already since the tagbits were not "dropped", just the same capturing in a test
3825
	public void testSE7AnnotationCopy() { // we were dropping annotations here, but null analysis worked already since the tagbits were not "dropped", just the same capturing in a test
3781
		runNegativeTestWithLibs(
3826
		runNegativeTestWithLibs(
3782
			new String[] {
3827
			new String[] {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java (+4 lines)
Lines 373-378 Link Here
373
	public BoundSet inferInvocationType(BoundSet b1, TypeBinding expectedType, InvocationSite invocationSite, MethodBinding method)
373
	public BoundSet inferInvocationType(BoundSet b1, TypeBinding expectedType, InvocationSite invocationSite, MethodBinding method)
374
			throws InferenceFailureException 
374
			throws InferenceFailureException 
375
	{
375
	{
376
		// not JLS: simply ensure that null hints from the return type have been seen even in standalone contexts:
377
		if (expectedType == null && method.returnType != null)
378
			substitute(method.returnType); // result is ignore, the only effect is on InferenceVariable.nullHints
379
		//
376
		BoundSet previous = this.currentBounds.copy();
380
		BoundSet previous = this.currentBounds.copy();
377
		this.currentBounds = b1;
381
		this.currentBounds = b1;
378
		try {
382
		try {

Return to bug 434899