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 434602 | 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 (-1 / +84 lines)
Lines 36-42 public NullAnnotationTest(String name) { Link Here
36
// Static initializer to specify tests subset using TESTS_* static variables
36
// Static initializer to specify tests subset using TESTS_* static variables
37
// All specified tests which do not belong to the class are skipped...
37
// All specified tests which do not belong to the class are skipped...
38
static {
38
static {
39
//		TESTS_NAMES = new String[] { "testBug412076" };
39
		TESTS_NAMES = new String[] { "testBug434604" };
40
//		TESTS_NUMBERS = new int[] { 561 };
40
//		TESTS_NUMBERS = new int[] { 561 };
41
//		TESTS_RANGE = new int[] { 1, 2049 };
41
//		TESTS_RANGE = new int[] { 1, 2049 };
42
}
42
}
Lines 7436-7439 public void testBug434374c() { Link Here
7436
		getCompilerOptions(),
7436
		getCompilerOptions(),
7437
		"");
7437
		"");
7438
}
7438
}
7439
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=434602
7440
// Possible error with inferred null annotations leading to contradictory null annotations
7441
public void testBug434602() {
7442
	if (this.complianceLevel < ClassFileConstants.JDK1_8)
7443
		return;
7444
	runConformTestWithLibs(
7445
			new String[] {
7446
				"X.java",
7447
				"import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
7448
				"import org.eclipse.jdt.annotation.Nullable;\n" +
7449
				"\n" +
7450
				"class Y {}\n" +
7451
				"@NonNullByDefault\n" +
7452
				"class X {\n" +
7453
				"	void foo() {\n" +
7454
				"		X x = new X();\n" +
7455
				"		x.bar(); // Error: Contradictory null annotations before the fix\n" +
7456
				"	}\n" +
7457
				"\n" +
7458
				"	public <T extends Y> @Nullable T bar() {\n" +
7459
				"		return null;\n" +
7460
				"	}\n" +
7461
				"}\n"
7462
			},
7463
			getCompilerOptions(),
7464
			"");
7465
}
7466
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=434602
7467
//Possible error with inferred null annotations leading to contradictory null annotations
7468
//Method part of parameterized class.
7469
public void testBug434603() {
7470
	if (this.complianceLevel < ClassFileConstants.JDK1_8)
7471
		return;
7472
	runConformTestWithLibs(
7473
			new String[] {
7474
				"X.java",
7475
				"import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
7476
				"import org.eclipse.jdt.annotation.Nullable;\n" +
7477
				"\n" +
7478
				"class Y {}\n" +
7479
				"@NonNullByDefault\n" +
7480
				"class Z <T> {\n" +
7481
				"	void foo() {\n" +
7482
				"		Z<Y> z = new Z<Y>();\n" +
7483
				"		z.bar(); // Error: Contradictory null annotations before the fix\n" +
7484
				"	}\n" +
7485
				"\n" +
7486
				"	public @Nullable T bar() {\n" +
7487
				"		return null;\n" +
7488
				"	}\n" +
7489
				"}\n" +
7490
				"class X {}\n"
7491
			},
7492
			getCompilerOptions(),
7493
			"");
7494
}
7495
public void testBug434604() {
7496
	if (this.complianceLevel < ClassFileConstants.JDK1_8)
7497
		return;
7498
	runConformTestWithLibs(
7499
			new String[] {
7500
				"X.java",
7501
				"//import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
7502
				"import org.eclipse.jdt.annotation.Nullable;\n" +
7503
				"import org.eclipse.jdt.annotation.NonNull;\n" +
7504
				"\n" +
7505
				"class Y {}\n" +
7506
				"class Y2 extends Y {}\n" +
7507
				"\n" +
7508
				"//@NonNullByDefault\n" +
7509
				"class X {\n" +
7510
				"	void foo() {\n" +
7511
				"		X x = new X();\n" +
7512
				"		x.bar(new Y2()); \n" +
7513
				"	}\n" +
7514
				"	public <T extends @NonNull Y> @Nullable T bar(T t) {\n" +
7515
				"		return t;\n" +
7516
				"	}\n" +
7517
				"}\n"
7518
			},
7519
			getCompilerOptions(),
7520
			"");
7521
}
7439
}
7522
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java (+4 lines)
Lines 739-744 public class ParameterizedGenericMethodBinding extends ParameterizedMethodBindin Link Here
739
        // check this variable can be substituted given parameterized type
739
        // check this variable can be substituted given parameterized type
740
        if (originalVariable.rank < length && TypeBinding.equalsEquals(variables[originalVariable.rank], originalVariable)) {
740
        if (originalVariable.rank < length && TypeBinding.equalsEquals(variables[originalVariable.rank], originalVariable)) {
741
        	TypeBinding substitute = this.typeArguments[originalVariable.rank];
741
        	TypeBinding substitute = this.typeArguments[originalVariable.rank];
742
            if ((originalVariable.tagBits & TagBits.AnnotationNullable) == TagBits.AnnotationNullable
743
                && (substitute.tagBits & TagBits.AnnotationNonNull) == TagBits.AnnotationNonNull) {
744
                substitute = substitute.unannotated();
745
            }
742
        	return originalVariable.hasTypeAnnotations() ? this.environment.createAnnotatedType(substitute, originalVariable.getTypeAnnotations()) : substitute;
746
        	return originalVariable.hasTypeAnnotations() ? this.environment.createAnnotatedType(substitute, originalVariable.getTypeAnnotations()) : substitute;
743
        }
747
        }
744
	    return originalVariable;
748
	    return originalVariable;
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java (+4 lines)
Lines 1188-1193 public class ParameterizedTypeBinding extends ReferenceBinding implements Substi Link Here
1188
					    	return originalVariable;
1188
					    	return originalVariable;
1189
					 }
1189
					 }
1190
			    	 TypeBinding substitute = currentType.arguments[originalVariable.rank];
1190
			    	 TypeBinding substitute = currentType.arguments[originalVariable.rank];
1191
			         if ((originalVariable.tagBits & TagBits.AnnotationNullable) == TagBits.AnnotationNullable
1192
			             && (substitute.tagBits & TagBits.AnnotationNonNull) == TagBits.AnnotationNonNull) {
1193
			             substitute = substitute.unannotated();
1194
			         }
1191
			    	 return originalVariable.hasTypeAnnotations() ? this.environment.createAnnotatedType(substitute, originalVariable.getTypeAnnotations()) : substitute;
1195
			    	 return originalVariable.hasTypeAnnotations() ? this.environment.createAnnotatedType(substitute, originalVariable.getTypeAnnotations()) : substitute;
1192
			    }	
1196
			    }	
1193
			}
1197
			}

Return to bug 434602