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 (+70 lines)
Lines 3220-3225 Link Here
3220
			"Null type safety (type annotations): The expression of type \'X<String>\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + 
3220
			"Null type safety (type annotations): The expression of type \'X<String>\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + 
3221
			"----------\n");
3221
			"----------\n");
3222
	}
3222
	}
3223
3224
	// introduce unrelated method lookup before the bogus one
3225
	public void testBug416182a() { 
3226
		runNegativeTestWithLibs(
3227
			new String[] {
3228
				"X.java",
3229
				"import org.eclipse.jdt.annotation.NonNull;\n" + 
3230
				"import org.eclipse.jdt.annotation.Nullable;\n" + 
3231
				"\n" + 
3232
				"public class X<T> {\n" +
3233
				"	T foo(@NonNull T t) {\n" + 
3234
				"		return t;\n" + 
3235
				"	}\n" +
3236
				"	void foo() {}\n" + 
3237
				"	public static void main(String[] args) {\n" + 
3238
				"		X<@Nullable String> xs = new X<String>();\n" +
3239
				"		xs.foo();\n" + 
3240
				"		xs.foo(null);\n" + 
3241
				"	}\n" + 
3242
				"	\n" +
3243
				"	public void test(X<String> x) {\n" + 
3244
				"		X<@Nullable String> xs = x;\n" + 
3245
				"		xs.bar(null);\n" + 
3246
				"	}\n" + 
3247
				"	public void bar(T t) {}\n" + 
3248
				"\n" + 
3249
				"}\n"
3250
			},
3251
			getCompilerOptions(),
3252
			"----------\n" + 
3253
			"1. ERROR in X.java (at line 12)\n" + 
3254
			"	xs.foo(null);\n" + 
3255
			"	^^^^^^^^^^^^\n" + 
3256
			"Contradictory null annotations: method was inferred as \'@Nullable String foo(@NonNull @Nullable String)\', but only one of \'@NonNull\' and \'@Nullable\' can be effective at any location\n" + 
3257
			"----------\n" + 
3258
			"2. WARNING in X.java (at line 16)\n" + 
3259
			"	X<@Nullable String> xs = x;\n" + 
3260
			"	                         ^\n" + 
3261
			"Null type safety (type annotations): The expression of type \'X<String>\' needs unchecked conversion to conform to \'X<@Nullable String>\'\n" + 
3262
			"----------\n");
3263
	}
3223
	
3264
	
3224
	public void testBug416183() {
3265
	public void testBug416183() {
3225
		runConformTestWithLibs(
3266
		runConformTestWithLibs(
Lines 5157-5160 Link Here
5157
		getCompilerOptions(),
5198
		getCompilerOptions(),
5158
		"");
5199
		"");
5159
}
5200
}
5201
// NPE without the fix.
5202
public void testBug433478() {
5203
	runNegativeTestWithLibs(
5204
            new String[] {
5205
                "X.java",
5206
                "import org.eclipse.jdt.annotation.NonNullByDefault;\n" +
5207
                "import org.eclipse.jdt.annotation.Nullable;\n" +
5208
                "\n" +
5209
                "@NonNullByDefault class Y { }\n" +
5210
                "\n" +
5211
                "interface I<T> {\n" +
5212
                "       @Nullable T foo();\n" +
5213
                "}\n" +
5214
                "\n" +
5215
                "@NonNullByDefault \n" +
5216
                "class X implements I<Y> {\n" +
5217
                "       @Override\n" +
5218
                "       public Y foo() {\n" +
5219
                "               return null;\n" +
5220
                "       }\n" +
5221
                "}\n"
5222
            },
5223
            "----------\n" + 
5224
    		"1. ERROR in X.java (at line 14)\n" + 
5225
    		"	return null;\n" + 
5226
    		"	       ^^^^\n" + 
5227
    		"Null type mismatch: required \'@NonNull Y\' but the provided value is null\n" + 
5228
    		"----------\n");
5229
}
5160
}
5230
}
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/ProblemMethodBinding.java (-1 / +4 lines)
Lines 34-40 Link Here
34
public ProblemMethodBinding(MethodBinding closestMatch, char[] selector, TypeBinding[] args, int problemReason) {
34
public ProblemMethodBinding(MethodBinding closestMatch, char[] selector, TypeBinding[] args, int problemReason) {
35
	this(selector, args, problemReason);
35
	this(selector, args, problemReason);
36
	this.closestMatch = closestMatch;
36
	this.closestMatch = closestMatch;
37
	if (closestMatch != null && problemReason != ProblemReasons.Ambiguous) this.declaringClass = closestMatch.declaringClass;
37
	if (closestMatch != null && problemReason != ProblemReasons.Ambiguous) {
38
		this.declaringClass = closestMatch.declaringClass;
39
		this.returnType = closestMatch.returnType;
40
	}
38
}
41
}
39
/* API
42
/* API
40
* Answer the problem id associated with the receiver.
43
* Answer the problem id associated with the receiver.

Return to bug 433478