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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/FieldBinding.java (-2 / +2 lines)
Lines 108-115 Link Here
108
		// AND the invocationType and the declaringClass have a common enclosingType
108
		// AND the invocationType and the declaringClass have a common enclosingType
109
		receiverCheck: {
109
		receiverCheck: {
110
			if (receiverType != this.declaringClass) {
110
			if (receiverType != this.declaringClass) {
111
				// special tolerance for type variable direct bounds
111
				// special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
112
				if (receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
112
				if (scope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6 && receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
113
					break receiverCheck;
113
					break receiverCheck;
114
				return false;
114
				return false;
115
			}
115
			}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java (-2 / +2 lines)
Lines 287-294 Link Here
287
		// AND the invocationType and the declaringClass have a common enclosingType
287
		// AND the invocationType and the declaringClass have a common enclosingType
288
		receiverCheck: {
288
		receiverCheck: {
289
			if (receiverType != this.declaringClass) {
289
			if (receiverType != this.declaringClass) {
290
				// special tolerance for type variable direct bounds
290
				// special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
291
				if (receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
291
				if (scope.compilerOptions().complianceLevel <= ClassFileConstants.JDK1_6 && receiverType.isTypeVariable() && ((TypeVariableBinding) receiverType).isErasureBoundTo(this.declaringClass.erasure()))
292
					break receiverCheck;
292
					break receiverCheck;
293
				return false;
293
				return false;
294
			}
294
			}
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java (-2 / +2 lines)
Lines 226-235 Link Here
226
		// AND the invocationType and the receiver have a common enclosingType
226
		// AND the invocationType and the receiver have a common enclosingType
227
		receiverCheck: {
227
		receiverCheck: {
228
			if (!(receiverType == this || receiverType == enclosingType())) {
228
			if (!(receiverType == this || receiverType == enclosingType())) {
229
				// special tolerance for type variable direct bounds
229
				// special tolerance for type variable direct bounds, but only if compliance <= 1.6, see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
230
				if (receiverType.isTypeVariable()) {
230
				if (receiverType.isTypeVariable()) {
231
					TypeVariableBinding typeVariable = (TypeVariableBinding) receiverType;
231
					TypeVariableBinding typeVariable = (TypeVariableBinding) receiverType;
232
					if (typeVariable.isErasureBoundTo(erasure()) || typeVariable.isErasureBoundTo(enclosingType().erasure()))
232
					if (typeVariable.environment.globalOptions.complianceLevel <= ClassFileConstants.JDK1_6 && (typeVariable.isErasureBoundTo(erasure()) || typeVariable.isErasureBoundTo(enclosingType().erasure())))
233
						break receiverCheck;
233
						break receiverCheck;
234
				}
234
				}
235
				return false;
235
				return false;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java (-3 / +55 lines)
Lines 9016-9021 Link Here
9016
				"class Y extends Zork {\n" +
9016
				"class Y extends Zork {\n" +
9017
				"}\n"
9017
				"}\n"
9018
			},
9018
			},
9019
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
9019
			"----------\n" +
9020
			"----------\n" +
9020
			"1. WARNING in X.java (at line 6)\n" +
9021
			"1. WARNING in X.java (at line 6)\n" +
9021
			"	public int foo(T t) { return t.i + t.i() + T.M.j; }\n" +
9022
			"	public int foo(T t) { return t.i + t.i() + T.M.j; }\n" +
Lines 9029-9034 Link Here
9029
			"----------\n"
9030
			"----------\n"
9030
			// 5: operator + cannot be applied to int,<any>.j
9031
			// 5: operator + cannot be applied to int,<any>.j
9031
			// 5: incompatible type, found : <nulltype>, required: int
9032
			// 5: incompatible type, found : <nulltype>, required: int
9033
			:
9034
				
9035
			// 1.7+ output, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
9036
			"----------\n" + 
9037
			"1. ERROR in X.java (at line 6)\n" + 
9038
			"	public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + 
9039
			"	                               ^\n" + 
9040
			"The field X<T>.i is not visible\n" + 
9041
			"----------\n" + 
9042
			"2. ERROR in X.java (at line 6)\n" + 
9043
			"	public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + 
9044
			"	                                     ^\n" + 
9045
			"The method i() from the type X<T> is not visible\n" + 
9046
			"----------\n" + 
9047
			"3. ERROR in X.java (at line 6)\n" + 
9048
			"	public int foo(T t) { return t.i + t.i() + T.M.j; }\n" + 
9049
			"	                                           ^^^\n" + 
9050
			"The type T.M is not visible\n" + 
9051
			"----------\n" + 
9052
			"4. ERROR in X.java (at line 9)\n" + 
9053
			"	class Y extends Zork {\n" + 
9054
			"	                ^^^^\n" + 
9055
			"Zork cannot be resolved to a type\n" + 
9056
			"----------\n"
9032
		);
9057
		);
9033
	}
9058
	}
9034
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=72583
9059
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=72583
Lines 49782-49788 Link Here
49782
}
49807
}
49783
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 (visibility error for package private method)
49808
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=285002 (visibility error for package private method)
49784
public void test1458() {
49809
public void test1458() {
49785
	this.runConformTest(
49810
	this.runNegativeTest(
49786
			new String[] {
49811
			new String[] {
49787
					"CompilerBug.java",
49812
					"CompilerBug.java",
49788
					"public class CompilerBug {\n" +
49813
					"public class CompilerBug {\n" +
Lines 49806-49814 Link Here
49806
					"		      getClass().newInstance().privateInt = 10;\n" +
49831
					"		      getClass().newInstance().privateInt = 10;\n" +
49807
					"		      getClass().newInstance().packagePrivateInt = 10;\n" +
49832
					"		      getClass().newInstance().packagePrivateInt = 10;\n" +
49808
					"		      getClass().newInstance().protectedInt = 10;\n" +
49833
					"		      getClass().newInstance().protectedInt = 10;\n" +
49834
					"             Zork z;\n" +
49809
					"		   }\n" +
49835
					"		   }\n" +
49810
					"	}\n"
49836
					"	}\n",
49811
			});
49837
			},
49838
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
49839
			"----------\n" + 
49840
			"1. ERROR in CompilerBug.java (at line 22)\n" + 
49841
			"	Zork z;\n" + 
49842
			"	^^^^\n" + 
49843
			"Zork cannot be resolved to a type\n" + 
49844
			"----------\n" :
49845
				
49846
			// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622
49847
			"----------\n" + 
49848
			"1. ERROR in CompilerBug.java (at line 17)\n" + 
49849
			"	getClass().newInstance().privateMethod();\n" + 
49850
			"	                         ^^^^^^^^^^^^^\n" + 
49851
			"The method privateMethod() from the type CompilerBug is not visible\n" + 
49852
			"----------\n" + 
49853
			"2. ERROR in CompilerBug.java (at line 19)\n" + 
49854
			"	getClass().newInstance().privateInt = 10;\n" + 
49855
			"	                         ^^^^^^^^^^\n" + 
49856
			"The field CompilerBug.privateInt is not visible\n" + 
49857
			"----------\n" + 
49858
			"3. ERROR in CompilerBug.java (at line 22)\n" + 
49859
			"	Zork z;\n" + 
49860
			"	^^^^\n" + 
49861
			"Zork cannot be resolved to a type\n" + 
49862
			"----------\n"
49863
			);
49812
}
49864
}
49813
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=295698
49865
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=295698
49814
public void test1459() {
49866
public void test1459() {
(-)src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest.java (+147 lines)
Lines 15-20 Link Here
15
15
16
import junit.framework.Test;
16
import junit.framework.Test;
17
17
18
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
18
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
19
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
19
20
20
public class GenericsRegressionTest extends AbstractComparableTest {
21
public class GenericsRegressionTest extends AbstractComparableTest {
Lines 1157-1160 Link Here
1157
			true,
1158
			true,
1158
			customOptions);
1159
			customOptions);
1159
}
1160
}
1161
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - different packages)
1162
public void test334622a() {
1163
	this.runNegativeTest(
1164
			new String[] {
1165
					"p/X.java",
1166
					"package p;\n" +
1167
					"public class X {\n" +
1168
					"    private Object foo;\n" +
1169
					"}\n",
1170
					"q/Y.java",
1171
					"package q;\n" +
1172
					"import p.X;\n" +
1173
					"public class Y {\n" +
1174
					"    public <T extends X> void test(T t) {\n" +
1175
					"        System.out.println(t.foo);\n" +
1176
					"    }\n" +
1177
					"    Zork z;\n" +
1178
					"}\n"
1179
			},
1180
			"----------\n" + 
1181
			"1. WARNING in p\\X.java (at line 3)\n" + 
1182
			"	private Object foo;\n" + 
1183
			"	               ^^^\n" + 
1184
			"The value of the field X.foo is not used\n" + 
1185
			"----------\n" + 
1186
			"----------\n" + 
1187
			"1. ERROR in q\\Y.java (at line 5)\n" + 
1188
			"	System.out.println(t.foo);\n" + 
1189
			"	                     ^^^\n" + 
1190
			"The field X.foo is not visible\n" + 
1191
			"----------\n" + 
1192
			"2. ERROR in q\\Y.java (at line 7)\n" + 
1193
			"	Zork z;\n" + 
1194
			"	^^^^\n" + 
1195
			"Zork cannot be resolved to a type\n" + 
1196
			"----------\n");
1197
}
1198
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (private access - same package)
1199
public void test334622b() {
1200
	this.runNegativeTest(
1201
			new String[] {
1202
					"p/X.java",
1203
					"package p;\n" +
1204
					"public class X {\n" +
1205
					"    private Object foo;\n" +
1206
					"}\n",
1207
					"p/Y.java",
1208
					"package p;\n" +
1209
					"public class Y {\n" +
1210
					"    public <T extends X> void test(T t) {\n" +
1211
					"        System.out.println(t.foo);\n" +
1212
					"    }\n" +
1213
					"    Zork z;\n" +
1214
					"}\n"
1215
			},
1216
			"----------\n" + 
1217
			"1. WARNING in p\\X.java (at line 3)\n" + 
1218
			"	private Object foo;\n" + 
1219
			"	               ^^^\n" + 
1220
			"The value of the field X.foo is not used\n" + 
1221
			"----------\n" + 
1222
			"----------\n" + 
1223
			"1. ERROR in p\\Y.java (at line 4)\n" + 
1224
			"	System.out.println(t.foo);\n" + 
1225
			"	                     ^^^\n" + 
1226
			"The field X.foo is not visible\n" + 
1227
			"----------\n" + 
1228
			"2. ERROR in p\\Y.java (at line 6)\n" + 
1229
			"	Zork z;\n" + 
1230
			"	^^^^\n" + 
1231
			"Zork cannot be resolved to a type\n" + 
1232
			"----------\n");
1233
}
1234
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (member of type variable shouldn't contain private members of class constituting intersection type)
1235
public void test334622c() {
1236
	this.runNegativeTest(
1237
			new String[] {
1238
					"X.java",
1239
					"public class X {\n" +
1240
					"    private Object foo;\n" +
1241
					"    public <T extends X> void test(T t) {\n" +
1242
					"        System.out.println(t.foo);\n" +
1243
					"        Zork z;\n" +
1244
					"    }\n" +
1245
					"}\n"
1246
			},
1247
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
1248
			"----------\n" + 
1249
			"1. ERROR in X.java (at line 5)\n" + 
1250
			"	Zork z;\n" + 
1251
			"	^^^^\n" + 
1252
			"Zork cannot be resolved to a type\n" + 
1253
			"----------\n" : 
1254
				
1255
			// 1.7+ output.	
1256
			"----------\n" + 
1257
			"1. WARNING in X.java (at line 2)\n" + 
1258
			"	private Object foo;\n" + 
1259
			"	               ^^^\n" + 
1260
			"The value of the field X.foo is not used\n" + 
1261
			"----------\n" + 
1262
			"2. ERROR in X.java (at line 4)\n" + 
1263
			"	System.out.println(t.foo);\n" + 
1264
			"	                     ^^^\n" + 
1265
			"The field X.foo is not visible\n" + 
1266
			"----------\n" + 
1267
			"3. ERROR in X.java (at line 5)\n" + 
1268
			"	Zork z;\n" + 
1269
			"	^^^^\n" + 
1270
			"Zork cannot be resolved to a type\n" + 
1271
			"----------\n");
1272
}
1273
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=334622 (member of type variable shouldn't contain private members of class constituting intersection type)
1274
public void test334622d() {
1275
	this.runNegativeTest(
1276
			new String[] {
1277
					"X.java",
1278
					"public class X {\n" +
1279
					"    private Object foo() { return null; }\n" +
1280
					"    public <T extends X> void test(T t) {\n" +
1281
					"        t.foo();\n" +
1282
					"        Zork z;\n" +
1283
					"    }\n" +
1284
					"}\n"
1285
			},
1286
			this.complianceLevel <= ClassFileConstants.JDK1_6 ?
1287
			"----------\n" + 
1288
			"1. ERROR in X.java (at line 5)\n" + 
1289
			"	Zork z;\n" + 
1290
			"	^^^^\n" + 
1291
			"Zork cannot be resolved to a type\n" + 
1292
			"----------\n" : 
1293
				
1294
			// 1.7+ output.	
1295
			"----------\n" + 
1296
			"1. ERROR in X.java (at line 4)\n" + 
1297
			"	t.foo();\n" + 
1298
			"	  ^^^\n" + 
1299
			"The method foo() from the type X is not visible\n" + 
1300
			"----------\n" + 
1301
			"2. ERROR in X.java (at line 5)\n" + 
1302
			"	Zork z;\n" + 
1303
			"	^^^^\n" + 
1304
			"Zork cannot be resolved to a type\n" + 
1305
			"----------\n");
1306
}
1160
}
1307
}

Return to bug 334622