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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (+51 lines)
Lines 41390-41393 Link Here
41390
			"Zork cannot be resolved to a type\n" + 
41390
			"Zork cannot be resolved to a type\n" + 
41391
			"----------\n");
41391
			"----------\n");
41392
}
41392
}
41393
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619
41394
public void test1338() {
41395
	this.runNegativeTest(
41396
			new String[] {
41397
				"X.java", // =================
41398
				"public class X {\n" + 
41399
				"        void m(Object someObject, Integer intObject) {\n" + 
41400
				"                Exception class1 = someObject.getClass();\n" + 
41401
				"                Exception class2 = intObject.getClass();\n" + 
41402
				"        }\n" + 
41403
				"}\n", // =================
41404
			},
41405
			"----------\n" + 
41406
			"1. ERROR in X.java (at line 3)\n" + 
41407
			"	Exception class1 = someObject.getClass();\n" + 
41408
			"	                   ^^^^^^^^^^^^^^^^^^^^^\n" + 
41409
			"Type mismatch: cannot convert from Class<capture#1-of ? extends Object> to Exception\n" + 
41410
			"----------\n" + 
41411
			"2. ERROR in X.java (at line 4)\n" + 
41412
			"	Exception class2 = intObject.getClass();\n" + 
41413
			"	                   ^^^^^^^^^^^^^^^^^^^^\n" + 
41414
			"Type mismatch: cannot convert from Class<capture#2-of ? extends Integer> to Exception\n" + 
41415
			"----------\n");
41416
}
41417
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619 - variation
41418
public void test1339() {
41419
	this.runNegativeTest(
41420
			new String[] {
41421
				"java/lang/Object.java", // =================
41422
				"package java.lang;\n" + 
41423
				"\n" + 
41424
				"public class Object {\n" + 
41425
				"	void foo() {\n" + 
41426
				"		Exception e1 = getClass();\n" + 
41427
				"		Exception e2 = this.getClass();\n" + 
41428
				"	}\n" + 
41429
				"	public Class<?> getClass() { return null; }\n" +
41430
				"}\n", // =================
41431
			},
41432
			"----------\n" + 
41433
			"1. ERROR in java\\lang\\Object.java (at line 5)\n" + 
41434
			"	Exception e1 = getClass();\n" + 
41435
			"	               ^^^^^^^^^^\n" + 
41436
			"Type mismatch: cannot convert from Class<capture#1-of ? extends Object> to Exception\n" + 
41437
			"----------\n" + 
41438
			"2. ERROR in java\\lang\\Object.java (at line 6)\n" + 
41439
			"	Exception e2 = this.getClass();\n" + 
41440
			"	               ^^^^^^^^^^^^^^^\n" + 
41441
			"Type mismatch: cannot convert from Class<capture#2-of ? extends Object> to Exception\n" + 
41442
			"----------\n");
41443
}
41393
}
41444
}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/Scope.java (-6 / +3 lines)
Lines 774-781 Link Here
774
			unitScope.recordTypeReferences(exactMethod.thrownExceptions);
774
			unitScope.recordTypeReferences(exactMethod.thrownExceptions);
775
			// special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
775
			// special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
776
			if (receiverType.isInterface() || exactMethod.canBeSeenBy(receiverType, invocationSite, this)) {
776
			if (receiverType.isInterface() || exactMethod.canBeSeenBy(receiverType, invocationSite, this)) {
777
				if (receiverType.id != T_JavaLangObject
777
				if (argumentTypes == Binding.NO_PARAMETERS
778
					&& argumentTypes == Binding.NO_PARAMETERS
779
				    && CharOperation.equals(selector, GETCLASS)
778
				    && CharOperation.equals(selector, GETCLASS)
780
				    && exactMethod.returnType.isParameterizedType()/*1.5*/) {
779
				    && exactMethod.returnType.isParameterizedType()/*1.5*/) {
781
						return ParameterizedMethodBinding.instantiateGetClass(receiverType, exactMethod, this);
780
						return ParameterizedMethodBinding.instantiateGetClass(receiverType, exactMethod, this);
Lines 1818-1825 Link Here
1818
											invocationSite.setActualReceiverType(receiverType);
1817
											invocationSite.setActualReceiverType(receiverType);
1819
										}
1818
										}
1820
										// special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
1819
										// special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
1821
										if (receiverType.id != T_JavaLangObject
1820
										if (argumentTypes == Binding.NO_PARAMETERS
1822
											&& argumentTypes == Binding.NO_PARAMETERS
1823
										    && CharOperation.equals(selector, GETCLASS)
1821
										    && CharOperation.equals(selector, GETCLASS)
1824
										    && methodBinding.returnType.isParameterizedType()/*1.5*/) {
1822
										    && methodBinding.returnType.isParameterizedType()/*1.5*/) {
1825
												return ParameterizedMethodBinding.instantiateGetClass(receiverType, methodBinding, this);
1823
												return ParameterizedMethodBinding.instantiateGetClass(receiverType, methodBinding, this);
Lines 2078-2085 Link Here
2078
				return methodBinding;
2076
				return methodBinding;
2079
2077
2080
			// special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
2078
			// special treatment for Object.getClass() in 1.5 mode (substitute parameterized return type)
2081
			if (receiverType.id != T_JavaLangObject
2079
			if (argumentTypes == Binding.NO_PARAMETERS
2082
				&& argumentTypes == Binding.NO_PARAMETERS
2083
			    && CharOperation.equals(selector, GETCLASS)
2080
			    && CharOperation.equals(selector, GETCLASS)
2084
			    && methodBinding.returnType.isParameterizedType()/*1.5*/) {
2081
			    && methodBinding.returnType.isParameterizedType()/*1.5*/) {
2085
					return ParameterizedMethodBinding.instantiateGetClass(receiverType, methodBinding, this);
2082
					return ParameterizedMethodBinding.instantiateGetClass(receiverType, methodBinding, this);

Return to bug 234619