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 433478 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullTypeAnnotationTest.java (+29 lines)
Lines 5157-5160 public void testBug433586() { Link Here
5157
		getCompilerOptions(),
5157
		getCompilerOptions(),
5158
		"");
5158
		"");
5159
}
5159
}
5160
// NPE without the fix.
5161
public void testBug433478() {
5162
	runNegativeTestWithLibs(
5163
            new String[] {
5164
                "X.java",
5165
                "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
5166
                "import org.eclipse.jdt.annotation.Nullable;\n" +
5167
                "\n" +
5168
                "@NonNullByDefault class Y { }\n" +
5169
                "\n" +
5170
                "interface I<T> {\n" +
5171
                "       @Nullable T foo();\n" +
5172
                "}\n" +
5173
                "\n" +
5174
                "@NonNullByDefault \n" +
5175
                "class X implements I<Y> {\n" +
5176
                "       @Override\n" +
5177
                "       public Y foo() {\n" +
5178
                "               return null;\n" +
5179
                "       }\n" +
5180
                "}\n"
5181
            },
5182
            "----------\n" +
5183
            "1. ERROR in X.java (at line 13)\n" +
5184
            "	public Y foo() {\n" +
5185
            "	       ^\n" +
5186
            "The return type is incompatible with I<Y>.foo()\n" +
5187
            "----------\n");
5188
}
5160
}
5189
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/NullAnnotationMatching.java (-5 / +11 lines)
Lines 364-370 public class NullAnnotationMatching { Link Here
364
	 * Problems are either reported directly (if scope != null) or by returning a ProblemMethodBinding.
364
	 * Problems are either reported directly (if scope != null) or by returning a ProblemMethodBinding.
365
	 */
365
	 */
366
	public static MethodBinding checkForContraditions(
366
	public static MethodBinding checkForContraditions(
367
			final MethodBinding method, final InvocationSite invocationSite, final Scope scope) {
367
			final MethodBinding method, final InvocationSite invocationSite, final Scope scope, TypeBinding returnType) {
368
		
368
		
369
		class SearchContradictions extends TypeBindingVisitor {
369
		class SearchContradictions extends TypeBindingVisitor {
370
			ReferenceBinding typeWithContradiction;
370
			ReferenceBinding typeWithContradiction;
Lines 389-396 public class NullAnnotationMatching { Link Here
389
		SearchContradictions searchContradiction = new SearchContradictions();
389
		SearchContradictions searchContradiction = new SearchContradictions();
390
		TypeBindingVisitor.visit(searchContradiction, method.returnType);
390
		TypeBindingVisitor.visit(searchContradiction, method.returnType);
391
		if (searchContradiction.typeWithContradiction != null) {
391
		if (searchContradiction.typeWithContradiction != null) {
392
			if (scope == null)
392
			if (scope == null) {
393
				return new ProblemMethodBinding(method, method.selector, method.parameters, ProblemReasons.ContradictoryNullAnnotations);
393
				ProblemMethodBinding problem = new ProblemMethodBinding(method, method.selector, method.parameters, ProblemReasons.ContradictoryNullAnnotations);
394
				problem.returnType = returnType;
395
				return problem;
396
			}
394
			scope.problemReporter().contradictoryNullAnnotationsInferred(method, invocationSite);
397
			scope.problemReporter().contradictoryNullAnnotationsInferred(method, invocationSite);
395
			// note: if needed, we might want to update the method by removing the contradictory annotations??
398
			// note: if needed, we might want to update the method by removing the contradictory annotations??
396
			return method;
399
			return method;
Lines 402-409 public class NullAnnotationMatching { Link Here
402
		for (int i = 0; i < method.parameters.length; i++) {
405
		for (int i = 0; i < method.parameters.length; i++) {
403
			TypeBindingVisitor.visit(searchContradiction, method.parameters[i]);
406
			TypeBindingVisitor.visit(searchContradiction, method.parameters[i]);
404
			if (searchContradiction.typeWithContradiction != null) {
407
			if (searchContradiction.typeWithContradiction != null) {
405
				if (scope == null)
408
				if (scope == null) {
406
					return new ProblemMethodBinding(method, method.selector, method.parameters, ProblemReasons.ContradictoryNullAnnotations);
409
					ProblemMethodBinding problem = new ProblemMethodBinding(method, method.selector, method.parameters, ProblemReasons.ContradictoryNullAnnotations);
410
					problem.returnType = method.returnType;
411
					return problem;
412
				}
407
				if (arguments != null && i < arguments.length)
413
				if (arguments != null && i < arguments.length)
408
					scope.problemReporter().contradictoryNullAnnotationsInferred(method, arguments[i]);
414
					scope.problemReporter().contradictoryNullAnnotationsInferred(method, arguments[i]);
409
				else
415
				else
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/InferenceContext18.java (-4 / +6 lines)
Lines 528-534 public class InferenceContext18 { Link Here
528
				if (solutions != null) {
528
				if (solutions != null) {
529
					finalMethod = this.environment.createParameterizedGenericMethod(original, solutions);
529
					finalMethod = this.environment.createParameterizedGenericMethod(original, solutions);
530
					if (this.scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled)
530
					if (this.scope.compilerOptions().isAnnotationBasedNullAnalysisEnabled)
531
						NullAnnotationMatching.checkForContraditions(finalMethod, invocation, this.scope);
531
						NullAnnotationMatching.checkForContraditions(finalMethod, invocation, this.scope, null);
532
					invocation.registerInferenceContext(finalMethod, this);
532
					invocation.registerInferenceContext(finalMethod, this);
533
					this.solutionsPerTargetType.put(targetType, new Solution(finalMethod, result));
533
					this.solutionsPerTargetType.put(targetType, new Solution(finalMethod, result));
534
				}
534
				}
Lines 1446-1455 public class InferenceContext18 { Link Here
1446
					ReferenceBinding declaringClass = original.declaringClass;
1446
					ReferenceBinding declaringClass = original.declaringClass;
1447
					TypeBinding[] arguments = getSolutions(declaringClass.typeVariables(), innerMessage, bounds);
1447
					TypeBinding[] arguments = getSolutions(declaringClass.typeVariables(), innerMessage, bounds);
1448
					declaringClass = this.environment.createParameterizedType(declaringClass, arguments, declaringClass.enclosingType());
1448
					declaringClass = this.environment.createParameterizedType(declaringClass, arguments, declaringClass.enclosingType());
1449
					original = ((ParameterizedTypeBinding)declaringClass).createParameterizedMethod(original);
1449
					ParameterizedMethodBinding parameterizedMethod = ((ParameterizedTypeBinding)declaringClass).createParameterizedMethod(original);
1450
					inner.checkAgainstFinalTargetType(innerTargetType, this.scope);	
1450
					inner.checkAgainstFinalTargetType(innerTargetType, this.scope);	
1451
					if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled)
1451
					if (this.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled) {
1452
						NullAnnotationMatching.checkForContraditions(original, innerMessage, this.scope);
1452
						NullAnnotationMatching.checkForContraditions(parameterizedMethod, innerMessage, this.scope,	null);
1453
					}
1454
					original = parameterizedMethod;
1453
				}
1455
				}
1454
				
1456
				
1455
				// apply results of the combined inference onto the binding of the inner invocation:
1457
				// apply results of the combined inference onto the binding of the inner invocation:
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedGenericMethodBinding.java (-1 / +1 lines)
Lines 162-168 public class ParameterizedGenericMethodBinding extends ParameterizedMethodBindin Link Here
162
							}
162
							}
163
							if (invocationTypeInferred) {
163
							if (invocationTypeInferred) {
164
								if (compilerOptions.isAnnotationBasedNullAnalysisEnabled)
164
								if (compilerOptions.isAnnotationBasedNullAnalysisEnabled)
165
									NullAnnotationMatching.checkForContraditions(methodSubstitute, invocationSite, scope);
165
									NullAnnotationMatching.checkForContraditions(methodSubstitute, invocationSite, scope, null);
166
								infCtx18.rebindInnerPolies(result, methodSubstitute.parameters);
166
								infCtx18.rebindInnerPolies(result, methodSubstitute.parameters);
167
								return methodSubstitute.boundCheck18(scope, arguments);
167
								return methodSubstitute.boundCheck18(scope, arguments);
168
							} else {
168
							} else {
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ParameterizedTypeBinding.java (-4 / +7 lines)
Lines 672-679 public class ParameterizedTypeBinding extends ReferenceBinding implements Substi Link Here
672
		    for (int i = 0; i < length; i++) {
672
		    for (int i = 0; i < length; i++) {
673
		    	// substitute methods, so as to get updated declaring class at least
673
		    	// substitute methods, so as to get updated declaring class at least
674
	            parameterizedMethods[i] = createParameterizedMethod(originalMethods[i]);
674
	            parameterizedMethods[i] = createParameterizedMethod(originalMethods[i]);
675
	            if (useNullTypeAnnotations)
675
	            if (useNullTypeAnnotations) {
676
	            	parameterizedMethods[i] = NullAnnotationMatching.checkForContraditions(parameterizedMethods[i], null, null);
676
                    parameterizedMethods[i] = NullAnnotationMatching.checkForContraditions(parameterizedMethods[i], null, null,
677
                    		originalMethods[i].returnType);
678
	            }
677
		    }
679
		    }
678
		    if (this.methods == null) {
680
		    if (this.methods == null) {
679
				MethodBinding[] temp = new MethodBinding[length];
681
				MethodBinding[] temp = new MethodBinding[length];
Lines 945-952 public class ParameterizedTypeBinding extends ReferenceBinding implements Substi Link Here
945
		    for (int i = 0; i < length; i++) {
947
		    for (int i = 0; i < length; i++) {
946
		    	// substitute all methods, so as to get updated declaring class at least
948
		    	// substitute all methods, so as to get updated declaring class at least
947
	            parameterizedMethods[i] = createParameterizedMethod(originalMethods[i]);
949
	            parameterizedMethods[i] = createParameterizedMethod(originalMethods[i]);
948
	            if (useNullTypeAnnotations)
950
	            if (useNullTypeAnnotations) {
949
	            	parameterizedMethods[i] = NullAnnotationMatching.checkForContraditions(parameterizedMethods[i], null, null);
951
                    parameterizedMethods[i] = NullAnnotationMatching.checkForContraditions(parameterizedMethods[i], null, null, originalMethods[i].returnType);
952
	            }
950
		    }
953
		    }
951
954
952
		    this.methods = parameterizedMethods;
955
		    this.methods = parameterizedMethods;

Return to bug 433478