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

Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/lookup/ClassScope.java (-1 / +20 lines)
Lines 11-16 Link Here
11
package org.eclipse.jdt.internal.compiler.lookup;
11
package org.eclipse.jdt.internal.compiler.lookup;
12
12
13
import java.util.HashMap;
13
import java.util.HashMap;
14
import java.util.Iterator;
14
import java.util.Map;
15
import java.util.Map;
15
16
16
import org.eclipse.jdt.core.compiler.CharOperation;
17
import org.eclipse.jdt.core.compiler.CharOperation;
Lines 1028-1035 Link Here
1028
		SourceTypeBinding sourceType = this.referenceContext.binding;
1029
		SourceTypeBinding sourceType = this.referenceContext.binding;
1029
		if ((sourceType.tagBits & TagBits.BeginHierarchyCheck) == 0) {
1030
		if ((sourceType.tagBits & TagBits.BeginHierarchyCheck) == 0) {
1030
			sourceType.tagBits |= TagBits.BeginHierarchyCheck;
1031
			sourceType.tagBits |= TagBits.BeginHierarchyCheck;
1032
			environment().typesBeingConnected.add(sourceType);
1031
			boolean noProblems = connectSuperclass();
1033
			boolean noProblems = connectSuperclass();
1032
			noProblems &= connectSuperInterfaces();
1034
			noProblems &= connectSuperInterfaces();
1035
			environment().typesBeingConnected.remove(sourceType);
1033
			sourceType.tagBits |= TagBits.EndHierarchyCheck;
1036
			sourceType.tagBits |= TagBits.EndHierarchyCheck;
1034
			noProblems &= connectTypeVariables(this.referenceContext.typeParameters, false);
1037
			noProblems &= connectTypeVariables(this.referenceContext.typeParameters, false);
1035
			sourceType.tagBits |= TagBits.TypeVariablesAreConnected;
1038
			sourceType.tagBits |= TagBits.TypeVariablesAreConnected;
Lines 1065-1072 Link Here
1065
			return;
1068
			return;
1066
1069
1067
		sourceType.tagBits |= TagBits.BeginHierarchyCheck;
1070
		sourceType.tagBits |= TagBits.BeginHierarchyCheck;
1071
		environment().typesBeingConnected.add(sourceType);
1068
		boolean noProblems = connectSuperclass();
1072
		boolean noProblems = connectSuperclass();
1069
		noProblems &= connectSuperInterfaces();
1073
		noProblems &= connectSuperInterfaces();
1074
		environment().typesBeingConnected.remove(sourceType);
1070
		sourceType.tagBits |= TagBits.EndHierarchyCheck;
1075
		sourceType.tagBits |= TagBits.EndHierarchyCheck;
1071
		noProblems &= connectTypeVariables(this.referenceContext.typeParameters, false);
1076
		noProblems &= connectTypeVariables(this.referenceContext.typeParameters, false);
1072
		sourceType.tagBits |= TagBits.TypeVariablesAreConnected;
1077
		sourceType.tagBits |= TagBits.TypeVariablesAreConnected;
Lines 1168-1179 Link Here
1168
			org.eclipse.jdt.internal.compiler.ast.TypeReference ref = ((SourceTypeBinding) superType).scope.superTypeReference;
1173
			org.eclipse.jdt.internal.compiler.ast.TypeReference ref = ((SourceTypeBinding) superType).scope.superTypeReference;
1169
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133071
1174
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=133071
1170
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=121734
1175
			// https://bugs.eclipse.org/bugs/show_bug.cgi?id=121734
1171
			if (ref != null && (ref.resolvedType == null || ((ReferenceBinding) ref.resolvedType).isHierarchyBeingActivelyConnected())) {
1176
			if (ref != null && ref.resolvedType != null && ((ReferenceBinding) ref.resolvedType).isHierarchyBeingActivelyConnected()) {
1172
				problemReporter().hierarchyCircularity(sourceType, superType, reference);
1177
				problemReporter().hierarchyCircularity(sourceType, superType, reference);
1173
				sourceType.tagBits |= TagBits.HierarchyHasProblems;
1178
				sourceType.tagBits |= TagBits.HierarchyHasProblems;
1174
				superType.tagBits |= TagBits.HierarchyHasProblems;
1179
				superType.tagBits |= TagBits.HierarchyHasProblems;
1175
				return true;
1180
				return true;
1176
			}
1181
			}
1182
			if (ref != null && ref.resolvedType == null) {
1183
				// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885 Don't cry foul prematurely.
1184
				// Check the edges traversed to see if there really is a cycle.
1185
				char [] referredName = ref.getLastToken(); 
1186
				for (Iterator iter = environment().typesBeingConnected.iterator(); iter.hasNext();) {
1187
					SourceTypeBinding type = (SourceTypeBinding) iter.next();
1188
					if (CharOperation.equals(referredName, type.sourceName())) {
1189
						problemReporter().hierarchyCircularity(sourceType, superType, reference);
1190
						sourceType.tagBits |= TagBits.HierarchyHasProblems;
1191
						superType.tagBits |= TagBits.HierarchyHasProblems;
1192
						return true;
1193
					}
1194
				}
1195
			}
1177
		}
1196
		}
1178
		if ((superType.tagBits & TagBits.BeginHierarchyCheck) == 0)
1197
		if ((superType.tagBits & TagBits.BeginHierarchyCheck) == 0)
1179
			// ensure if this is a source superclass that it has already been checked
1198
			// ensure if this is a source superclass that it has already been checked
(-)compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java (+5 lines)
Lines 12-18 Link Here
12
12
13
import java.util.ArrayList;
13
import java.util.ArrayList;
14
import java.util.HashMap;
14
import java.util.HashMap;
15
import java.util.HashSet;
15
import java.util.Map;
16
import java.util.Map;
17
import java.util.Set;
16
18
17
import org.eclipse.jdt.core.compiler.CharOperation;
19
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.internal.compiler.ClassFilePool;
20
import org.eclipse.jdt.internal.compiler.ClassFilePool;
Lines 65-70 Link Here
65
	public MethodBinding arrayClone;
67
	public MethodBinding arrayClone;
66
68
67
	private ArrayList missingTypes;
69
	private ArrayList missingTypes;
70
	Set typesBeingConnected;
68
	public boolean isProcessingAnnotations = false;
71
	public boolean isProcessingAnnotations = false;
69
72
70
	final static int BUILD_FIELDS_AND_METHODS = 4;
73
	final static int BUILD_FIELDS_AND_METHODS = 4;
Lines 92-97 Link Here
92
	this.missingTypes = null;
95
	this.missingTypes = null;
93
	this.accessRestrictions = new HashMap(3);
96
	this.accessRestrictions = new HashMap(3);
94
	this.classFilePool = ClassFilePool.newInstance();
97
	this.classFilePool = ClassFilePool.newInstance();
98
	this.typesBeingConnected = new HashSet();
95
}
99
}
96
100
97
/**
101
/**
Lines 1348-1353 Link Here
1348
	this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3);
1352
	this.uniqueParameterizedGenericMethodBindings = new SimpleLookupTable(3);
1349
	this.uniqueGetClassMethodBinding = null;
1353
	this.uniqueGetClassMethodBinding = null;
1350
	this.missingTypes = null;
1354
	this.missingTypes = null;
1355
	this.typesBeingConnected = new HashSet();
1351
1356
1352
	for (int i = this.units.length; --i >= 0;)
1357
	for (int i = this.units.length; --i >= 0;)
1353
		this.units[i] = null;
1358
		this.units[i] = null;
(-)src/org/eclipse/jdt/core/tests/compiler/regression/InnerClass15Test.java (+284 lines)
Lines 139-144 Link Here
139
	"The type X is never used locally\n" + 
139
	"The type X is never used locally\n" + 
140
	"----------\n");
140
	"----------\n");
141
}
141
}
142
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
143
public void test005() {
144
	this.runNegativeTest(new String[] {
145
		"p1/GreenBox.java",
146
		"package p1;\n" +
147
		"import static p1.BrownBox.*;\n" +
148
		"public interface GreenBox {\n" +
149
		"    public static class Cat extends Object {}\n" +
150
		"}\n",
151
		"p1/BrownBox.java",
152
		"package p1;\n" +
153
		"import static p1.GreenBox.*;\n" +
154
		"public interface BrownBox {\n" +
155
		"    public static class BlackCat extends Cat {}\n" +
156
		"}\n",
157
	},
158
	"----------\n" + 
159
	"1. WARNING in p1\\GreenBox.java (at line 2)\n" + 
160
	"	import static p1.BrownBox.*;\n" + 
161
	"	              ^^^^^^^^^^^\n" + 
162
	"The import p1.BrownBox is never used\n" + 
163
	"----------\n");
164
}
165
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
166
public void test006() {
167
	this.runNegativeTest(new String[] {
168
		"p1/BrownBox.java",
169
		"package p1;\n" +
170
		"import static p1.GreenBox.*;\n" +
171
		"public interface BrownBox {\n" +
172
		"    public static class BlackCat extends Cat {}\n" +
173
		"}\n",
174
		"p1/GreenBox.java",
175
		"package p1;\n" +
176
		"import static p1.BrownBox.*;\n" +
177
		"public interface GreenBox {\n" +
178
		"    public static class Cat extends Object {}\n" +
179
		"}\n",
180
	},
181
	"----------\n" + 
182
	"1. WARNING in p1\\GreenBox.java (at line 2)\n" + 
183
	"	import static p1.BrownBox.*;\n" + 
184
	"	              ^^^^^^^^^^^\n" + 
185
	"The import p1.BrownBox is never used\n" + 
186
	"----------\n");
187
}
188
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
189
public void test007() {
190
	this.runNegativeTest(new String[] {
191
		"p1/BrownBox.java",
192
		"package p1;\n" +
193
		"import static p1.GreenBox.*;\n" +
194
		"public interface BrownBox {\n" +
195
		"    public static class BlackCat extends Cat {}\n" +
196
		"}\n",
197
		"p1/GreenBox.java",
198
		"package p1;\n" +
199
		"import static p1.BrownBox.*;\n" +
200
		"public interface GreenBox {\n" +
201
		"    public static class Cat extends java.lang.Object {}\n" +
202
		"}\n",
203
	},
204
	"----------\n" + 
205
	"1. WARNING in p1\\GreenBox.java (at line 2)\n" + 
206
	"	import static p1.BrownBox.*;\n" + 
207
	"	              ^^^^^^^^^^^\n" + 
208
	"The import p1.BrownBox is never used\n" + 
209
	"----------\n");
210
}
211
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
212
public void test008() {
213
	this.runNegativeTest(new String[] {
214
		"p1/BrownBox.java",
215
		"package p1;\n" +
216
		"import static p1.GreenBox.*;\n" +
217
		"public interface BrownBox {\n" +
218
		"    public static class BlackCat extends Cat {}\n" +
219
		"}\n",
220
		"p1/GreenBox.java",
221
		"package p1;\n" +
222
		"import static p1.BrownBox.*;\n" +
223
		"public interface GreenBox {\n" +
224
		"    public static class Cat extends BlackCat {}\n" +
225
		"}\n",
226
	},
227
	"----------\n" + 
228
	"1. ERROR in p1\\BrownBox.java (at line 4)\n" + 
229
	"	public static class BlackCat extends Cat {}\n" + 
230
	"	                    ^^^^^^^^\n" + 
231
	"The hierarchy of the type BlackCat is inconsistent\n" + 
232
	"----------\n" + 
233
	"----------\n" + 
234
	"1. ERROR in p1\\GreenBox.java (at line 4)\n" + 
235
	"	public static class Cat extends BlackCat {}\n" + 
236
	"	                                ^^^^^^^^\n" + 
237
	"Cycle detected: a cycle exists in the type hierarchy between GreenBox.Cat and BrownBox.BlackCat\n" + 
238
	"----------\n");
239
}
240
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
241
public void test009() {
242
	this.runNegativeTest(new String[] {
243
		"p1/GreenBox.java",
244
		"package p1;\n" +
245
		"import static p1.BrownBox.*;\n" +
246
		"public interface GreenBox {\n" +
247
		"    public static class Cat extends BlackCat {}\n" +
248
		"}\n",
249
		"p1/BrownBox.java",
250
		"package p1;\n" +
251
		"import static p1.GreenBox.*;\n" +
252
		"public interface BrownBox {\n" +
253
		"    public static class BlackCat extends Cat {}\n" +
254
		"}\n",
255
	},
256
	"----------\n" + 
257
	"1. ERROR in p1\\GreenBox.java (at line 4)\n" + 
258
	"	public static class Cat extends BlackCat {}\n" + 
259
	"	                    ^^^\n" + 
260
	"The hierarchy of the type Cat is inconsistent\n" + 
261
	"----------\n" + 
262
	"----------\n" + 
263
	"1. ERROR in p1\\BrownBox.java (at line 4)\n" + 
264
	"	public static class BlackCat extends Cat {}\n" + 
265
	"	                                     ^^^\n" + 
266
	"Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and GreenBox.Cat\n" + 
267
	"----------\n");
268
}
269
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
270
public void test0010() {
271
	this.runNegativeTest(new String[] {
272
		"p1/GreenBox.java",
273
		"package p1;\n" +
274
		"import static p1.BrownBox.*;\n" +
275
		"interface SuperInterface {\n" +
276
		"   public static class Cat extends BlackCat {}\n" +
277
		"}\n" +
278
		"public interface GreenBox {\n" +
279
		"}\n",
280
		"p1/BrownBox.java",
281
		"package p1;\n" +
282
		"import static p1.GreenBox.*;\n" +
283
		"public interface BrownBox {\n" +
284
		"    public static class BlackCat extends Cat {}\n" +
285
		"}\n",
286
	},
287
	"----------\n" + 
288
	"1. ERROR in p1\\GreenBox.java (at line 4)\n" + 
289
	"	public static class Cat extends BlackCat {}\n" + 
290
	"	                    ^^^\n" + 
291
	"The hierarchy of the type Cat is inconsistent\n" + 
292
	"----------\n" + 
293
	"----------\n" + 
294
	"1. ERROR in p1\\BrownBox.java (at line 4)\n" + 
295
	"	public static class BlackCat extends Cat {}\n" + 
296
	"	                                     ^^^\n" + 
297
	"Cat cannot be resolved to a type\n" + 
298
	"----------\n");
299
}
300
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
301
public void test0011() {
302
	this.runNegativeTest(new String[] {
303
		"p1/GreenBox.java",
304
		"package p1;\n" +
305
		"import static p1.BrownBox.*;\n" +
306
		"interface SuperInterface {\n" +
307
		"   public static class Cat extends BlackCat {}\n" +
308
		"}\n" +
309
		"public interface GreenBox extends SuperInterface {\n" +
310
		"}\n",
311
		"p1/BrownBox.java",
312
		"package p1;\n" +
313
		"import static p1.GreenBox.*;\n" +
314
		"public interface BrownBox {\n" +
315
		"    public static class BlackCat extends Cat {}\n" +
316
		"}\n",
317
	},
318
	"----------\n" + 
319
	"1. ERROR in p1\\GreenBox.java (at line 4)\n" + 
320
	"	public static class Cat extends BlackCat {}\n" + 
321
	"	                    ^^^\n" + 
322
	"The hierarchy of the type Cat is inconsistent\n" + 
323
	"----------\n" + 
324
	"----------\n" + 
325
	"1. ERROR in p1\\BrownBox.java (at line 4)\n" + 
326
	"	public static class BlackCat extends Cat {}\n" + 
327
	"	                                     ^^^\n" + 
328
	"Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and SuperInterface.Cat\n" + 
329
	"----------\n");
330
}
331
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
332
public void test0012() {
333
	this.runNegativeTest(new String[] {
334
		"p1/GreenBox.java",
335
		"package p1;\n" +
336
		"import static p1.BrownBox.*;\n" +
337
		"interface SuperInterface {\n" +
338
		"   public static class Cat extends BlackCat {}\n" +
339
		"}\n" +
340
		"public interface GreenBox extends SuperInterface {\n" +
341
		"}\n",
342
		"p1/BrownBox.java",
343
		"package p1;\n" +
344
		"import static p1.GreenBox.*;\n" +
345
		"public interface BrownBox {\n" +
346
		"    public static class BlackCat extends GreenBox.Cat {}\n" +
347
		"}\n",
348
	},
349
	"----------\n" + 
350
	"1. ERROR in p1\\GreenBox.java (at line 4)\n" + 
351
	"	public static class Cat extends BlackCat {}\n" + 
352
	"	                    ^^^\n" + 
353
	"The hierarchy of the type Cat is inconsistent\n" + 
354
	"----------\n" + 
355
	"----------\n" + 
356
	"1. ERROR in p1\\BrownBox.java (at line 4)\n" + 
357
	"	public static class BlackCat extends GreenBox.Cat {}\n" + 
358
	"	                                     ^^^^^^^^^^^^\n" + 
359
	"Cycle detected: a cycle exists in the type hierarchy between BrownBox.BlackCat and SuperInterface.Cat\n" + 
360
	"----------\n");
361
}
362
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
363
public void test0013() {
364
	this.runNegativeTest(new String[] {
365
		"cycle/X.java",
366
		"package cycle;\n" +
367
		"class X extends Y {}\n" +
368
		"class Y extends X {}\n",
369
	},
370
	"----------\n" + 
371
	"1. ERROR in cycle\\X.java (at line 2)\n" + 
372
	"	class X extends Y {}\n" + 
373
	"	      ^\n" + 
374
	"The hierarchy of the type X is inconsistent\n" + 
375
	"----------\n" + 
376
	"2. ERROR in cycle\\X.java (at line 3)\n" + 
377
	"	class Y extends X {}\n" + 
378
	"	                ^\n" + 
379
	"Cycle detected: a cycle exists in the type hierarchy between Y and X\n" + 
380
	"----------\n");
381
}
382
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=319885
383
public void test0014() {
384
	this.runNegativeTest(new String[] {
385
		"cycle/X.java",
386
		"package cycle;\n" +
387
		"class X extends Y {}\n" +
388
		"class Y extends Z {}\n" +
389
		"class Z extends A {}\n" +
390
		"class A extends B {}\n" +
391
		"class B extends C {}\n" +
392
		"class C extends X {}\n"
393
	},
394
	"----------\n" + 
395
	"1. ERROR in cycle\\X.java (at line 2)\n" + 
396
	"	class X extends Y {}\n" + 
397
	"	      ^\n" + 
398
	"The hierarchy of the type X is inconsistent\n" + 
399
	"----------\n" + 
400
	"2. ERROR in cycle\\X.java (at line 3)\n" + 
401
	"	class Y extends Z {}\n" + 
402
	"	      ^\n" + 
403
	"The hierarchy of the type Y is inconsistent\n" + 
404
	"----------\n" + 
405
	"3. ERROR in cycle\\X.java (at line 4)\n" + 
406
	"	class Z extends A {}\n" + 
407
	"	      ^\n" + 
408
	"The hierarchy of the type Z is inconsistent\n" + 
409
	"----------\n" + 
410
	"4. ERROR in cycle\\X.java (at line 5)\n" + 
411
	"	class A extends B {}\n" + 
412
	"	      ^\n" + 
413
	"The hierarchy of the type A is inconsistent\n" + 
414
	"----------\n" + 
415
	"5. ERROR in cycle\\X.java (at line 6)\n" + 
416
	"	class B extends C {}\n" + 
417
	"	      ^\n" + 
418
	"The hierarchy of the type B is inconsistent\n" + 
419
	"----------\n" + 
420
	"6. ERROR in cycle\\X.java (at line 7)\n" + 
421
	"	class C extends X {}\n" + 
422
	"	                ^\n" + 
423
	"Cycle detected: a cycle exists in the type hierarchy between C and X\n" + 
424
	"----------\n");
425
}
142
public static Class testClass() {
426
public static Class testClass() {
143
	return InnerClass15Test.class;
427
	return InnerClass15Test.class;
144
}
428
}

Return to bug 319885