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

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/dom/RunConverterTests.java (+1 lines)
Lines 27-32 Link Here
27
	return new Class[] {
27
	return new Class[] {
28
		ASTConverterTest.class,		
28
		ASTConverterTest.class,		
29
		ASTConverterTest2.class,
29
		ASTConverterTest2.class,
30
		ASTConverterBugsTest.class,		
30
		ASTConverterJavadocTest.class,
31
		ASTConverterJavadocTest.class,
31
		ASTConverter15Test.class,
32
		ASTConverter15Test.class,
32
		ASTConverter16Test.class,
33
		ASTConverter16Test.class,
(-)src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java (+88 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.core.tests.dom;
12
13
import java.io.IOException;
14
15
import junit.framework.Test;
16
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.jdt.core.ICompilationUnit;
19
import org.eclipse.jdt.core.dom.AST;
20
import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
21
import org.eclipse.jdt.core.dom.CompilationUnit;
22
import org.eclipse.jdt.core.dom.FieldDeclaration;
23
import org.eclipse.jdt.core.dom.ITypeBinding;
24
import org.eclipse.jdt.core.dom.Type;
25
26
public class ASTConverterBugsTest extends ConverterTestSetup {
27
	
28
	public void setUpSuite() throws Exception {
29
		PROJECT_SETUP = true; // do not copy Converter* directories
30
		super.setUpSuite();
31
		waitUntilIndexesReady();
32
	}
33
34
	public ASTConverterBugsTest(String name) {
35
		super(name);
36
	}
37
38
	public static Test suite() {
39
		return buildModelTestSuite(ASTConverterBugsTest.class);
40
	}
41
	
42
	/**
43
	 * @bug 186410: [dom] StackOverflowError due to endless superclass bindings hierarchy
44
	 * @test Ensures that the superclass of "java.lang.Object" class is null even when it's a recovered binding
45
	 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=186410"
46
	 */
47
	public void testBug186410() throws CoreException, IOException {
48
		try {
49
			createJavaProject("P", new String[] {""}, new String[0], "");
50
			createFile("P/A.java",
51
				"public class A {\n" +
52
				"	void method(){}\n" +
53
				"}"
54
			);
55
			ICompilationUnit cuA = getCompilationUnit("P/A.java");
56
			CompilationUnit unitA = (CompilationUnit) runConversion(AST.JLS3, cuA, true, false, true);
57
			AbstractTypeDeclaration typeA = (AbstractTypeDeclaration)unitA.types().get(0);
58
			ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
59
			assertEquals("Unexpected superclass", "Object", objectType .getName());
60
			ITypeBinding objectSuperclass = objectType.getSuperclass();
61
			assertNull("java.lang.Object should  not have any superclass", objectSuperclass);
62
		} finally {
63
			deleteProject("P");
64
		}
65
	}
66
	public void testBug186410b() throws CoreException, IOException {
67
		try {
68
			createJavaProject("P", new String[] {""}, new String[0], "");
69
			createFile("P/A.java",
70
				"public class A {\n" +
71
				"	Object field;\n" +
72
				"}"
73
			);
74
			ICompilationUnit cuA = getCompilationUnit("P/A.java");
75
			CompilationUnit unitA = (CompilationUnit) runConversion(AST.JLS3, cuA, true, false, true);
76
			AbstractTypeDeclaration type = (AbstractTypeDeclaration)unitA.types().get(0);
77
			FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
78
			Type fieldType = field.getType();
79
			ITypeBinding typeBinding = fieldType.resolveBinding();
80
			ITypeBinding objectType = typeBinding.createArrayType(2).getElementType();
81
			assertEquals("Unexpected superclass", "Object", objectType.getName());
82
			ITypeBinding objectSuperclass = objectType.getSuperclass();
83
			assertNull("java.lang.Object should  not have any superclass", objectSuperclass);
84
		} finally {
85
			deleteProject("P");
86
		}
87
	}
88
}
(-)dom/org/eclipse/jdt/core/dom/RecoveredTypeBinding.java (-6 / +49 lines)
Lines 15-22 Link Here
15
15
16
import org.eclipse.jdt.core.IJavaElement;
16
import org.eclipse.jdt.core.IJavaElement;
17
import org.eclipse.jdt.core.JavaModelException;
17
import org.eclipse.jdt.core.JavaModelException;
18
import org.eclipse.jdt.core.compiler.CharOperation;
18
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.ArrayBinding;
19
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
20
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope;
21
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
20
import org.eclipse.jdt.internal.compiler.util.Util;
22
import org.eclipse.jdt.internal.compiler.util.Util;
21
import org.eclipse.jdt.internal.core.CompilationUnit;
23
import org.eclipse.jdt.internal.core.CompilationUnit;
22
import org.eclipse.jdt.internal.core.PackageFragment;
24
import org.eclipse.jdt.internal.core.PackageFragment;
Lines 73-78 Link Here
73
	}
75
	}
74
76
75
	/* (non-Javadoc)
77
	/* (non-Javadoc)
78
	 * @see java.lang.Object#equals(java.lang.Object)
79
	 */
80
	public boolean equals(Object obj) {
81
	    if (this == obj) return true; // super implementation
82
	    if (obj instanceof RecoveredTypeBinding) {
83
		    RecoveredTypeBinding otherTypeBinding = (RecoveredTypeBinding) obj;
84
			if (this.innerTypeBinding != null) {
85
				return getName().equals(otherTypeBinding.getName()) && this.innerTypeBinding.equals(otherTypeBinding.innerTypeBinding);
86
			}
87
			if (this.referenceBinding != null && otherTypeBinding.referenceBinding != null) {
88
				ReferenceBinding currentReferenceTypeBinding = null;
89
				ReferenceBinding otherReferenceTypeBinding = null;
90
				if (this.referenceBinding.isArrayType() && otherTypeBinding.referenceBinding.isArrayType()) {
91
					ArrayBinding currentArrayBinding = (ArrayBinding) this.referenceBinding;
92
					ArrayBinding otherArrayBinding = (ArrayBinding) otherTypeBinding.referenceBinding;
93
					if (currentArrayBinding.leafComponentType instanceof ReferenceBinding &&
94
						otherArrayBinding.leafComponentType instanceof ReferenceBinding) {
95
						currentReferenceTypeBinding = (ReferenceBinding) currentArrayBinding.leafComponentType;
96
						otherReferenceTypeBinding = (ReferenceBinding) otherArrayBinding.leafComponentType;
97
					}
98
				} else if (this.referenceBinding instanceof ReferenceBinding &&
99
							otherTypeBinding.referenceBinding instanceof ReferenceBinding) {
100
					currentReferenceTypeBinding = (ReferenceBinding) this.referenceBinding;
101
					otherReferenceTypeBinding = (ReferenceBinding) otherTypeBinding.referenceBinding;
102
				}
103
				if (currentReferenceTypeBinding != null && otherReferenceTypeBinding != null) {
104
					return CharOperation.equals(currentReferenceTypeBinding.compoundName, otherReferenceTypeBinding.compoundName);
105
				}
106
		    } else {
107
				return getType().toString().equals(otherTypeBinding.toString());
108
			}
109
	    }
110
		return false;
111
    }
112
113
	/* (non-Javadoc)
76
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getBinaryName()
114
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getBinaryName()
77
	 */
115
	 */
78
	public String getBinaryName() {
116
	public String getBinaryName() {
Lines 206-219 Link Here
206
		if (this.innerTypeBinding != null) {
244
		if (this.innerTypeBinding != null) {
207
			return this.innerTypeBinding.getInternalName();
245
			return this.innerTypeBinding.getInternalName();
208
		} else if (this.referenceBinding != null) {
246
		} else if (this.referenceBinding != null) {
209
			org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding typeBinding = null;
247
			ReferenceBinding typeBinding = null;
210
			if (this.referenceBinding.isArrayType()) {
248
			if (this.referenceBinding.isArrayType()) {
211
				ArrayBinding arrayBinding = (ArrayBinding) this.referenceBinding;
249
				ArrayBinding arrayBinding = (ArrayBinding) this.referenceBinding;
212
				if (arrayBinding.leafComponentType instanceof org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) {
250
				if (arrayBinding.leafComponentType instanceof ReferenceBinding) {
213
					typeBinding = (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) arrayBinding.leafComponentType;
251
					typeBinding = (ReferenceBinding) arrayBinding.leafComponentType;
214
				}
252
				}
215
			} else if (this.referenceBinding instanceof org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) {
253
			} else if (this.referenceBinding instanceof ReferenceBinding) {
216
				typeBinding = (org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding) this.referenceBinding;
254
				typeBinding = (ReferenceBinding) this.referenceBinding;
217
			}
255
			}
218
			if (typeBinding != null) {
256
			if (typeBinding != null) {
219
				return new String(typeBinding.compoundName[typeBinding.compoundName.length - 1]);
257
				return new String(typeBinding.compoundName[typeBinding.compoundName.length - 1]);
Lines 244-250 Link Here
244
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getSuperclass()
282
	 * @see org.eclipse.jdt.core.dom.ITypeBinding#getSuperclass()
245
	 */
283
	 */
246
	public ITypeBinding getSuperclass() {
284
	public ITypeBinding getSuperclass() {
247
		return this.resolver.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
285
		ITypeBinding object = this.resolver.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
286
		if (equals(object)) {
287
			// avoid loop when java.lang.Object is also recovered
288
			return null;
289
		}
290
		return object;
248
	}
291
	}
249
292
250
	/* (non-Javadoc)
293
	/* (non-Javadoc)

Return to bug 186410