Bug 110594

Summary: [refactoring] CCE in Infer type argument refactoring
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: UIAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: neil, Olivier_Thomann
Version: 3.1.1   
Target Milestone: 3.3 M1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on: 110811    
Bug Blocks:    
Attachments:
Description Flags
updated ASTNode.java none

Description Martin Aeschlimann CLA 2005-09-26 10:22:28 EDT
3.1.1

I started to infer some type arguments myself, but then realized that the
refactoring might do this better.
However, on my already modified (but compiling code) the refactoring failed with
a ClassCastException

- get jdt.core from the 3.2 stream (I20050922), set 5.0 comoliance, change PDE
target location to a M2 build
- replace ASTNode with the attached file
- run ' Infer type argument ' on the 'dom' source folder in jdt.core

java.lang.ClassCastException:
org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.StandardType
	at
org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.RawType.initialize(RawType.java:30)
	at
org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment.createRawType(TypeEnvironment.java:388)
	at
org.eclipse.jdt.internal.corext.refactoring.typeconstraints.types.TypeEnvironment.create(TypeEnvironment.java:177)
	at
org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsTCModel.createTType(InferTypeArgumentsTCModel.java:299)
	at
org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsTCModel.getBoxedType(InferTypeArgumentsTCModel.java:309)
	at
org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsTCModel.makeTypeVariable(InferTypeArgumentsTCModel.java:375)
	at
org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsConstraintCreator.endVisit(InferTypeArgumentsConstraintCreator.java:124)
	at
org.eclipse.jdt.internal.corext.dom.HierarchicalASTVisitor.endVisit(HierarchicalASTVisitor.java:707)
	at org.eclipse.jdt.core.dom.SimpleType.accept0(SimpleType.java:138)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2497)
	at
org.eclipse.jdt.core.dom.VariableDeclarationStatement.accept0(VariableDeclarationStatement.java:271)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520)
	at org.eclipse.jdt.core.dom.Block.accept0(Block.java:135)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChild(ASTNode.java:2497)
	at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:501)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520)
	at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:483)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2520)
	at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:299)
	at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2450)
	at
org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring$2.run(InferTypeArgumentsRefactoring.java:194)
	at
org.eclipse.core.internal.runtime.InternalPlatform.run(InternalPlatform.java:1044)
	at org.eclipse.core.runtime.Platform.run(Platform.java:783)
	at
org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring$1.acceptAST(InferTypeArgumentsRefactoring.java:183)
	at
org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:691)
	at
org.eclipse.jdt.core.dom.CompilationUnitResolver.resolve(CompilationUnitResolver.java:455)
	at org.eclipse.jdt.core.dom.ASTParser.createASTs(ASTParser.java:664)
	at
org.eclipse.jdt.internal.corext.refactoring.generics.InferTypeArgumentsRefactoring.checkFinalConditions(InferTypeArgumentsRefactoring.java:178)
	at
org.eclipse.ltk.core.refactoring.CheckConditionsOperation.run(CheckConditionsOperation.java:84)
	at
org.eclipse.ltk.core.refactoring.CreateChangeOperation.run(CreateChangeOperation.java:114)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1719)
	at
org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:86)
	at
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:113)
Comment 1 Martin Aeschlimann CLA 2005-09-26 10:23:23 EDT
Created attachment 27511 [details]
updated ASTNode.java
Comment 2 Markus Keller CLA 2005-09-26 13:25:38 EDT
Self-contained example:

package dom;
import java.util.AbstractList;
import java.util.Iterator;
public class ASTNode {
	abstract class NodeList<E extends ASTNode> extends AbstractList<E> {
		abstract class Cursor implements Iterator {
			
		}
	}
	final void acceptChildren(ASTNode.NodeList children) {
		NodeList.Cursor cursor;
	}
}

The problem is that the reference NodeList.Cursor is raw, but its
typeDeclaration is not generic as expected, but a standard type. I'll
investigate, but I don't think that's for 3.1.1.
Comment 3 Markus Keller CLA 2005-09-27 07:29:55 EDT
An even smaller example:

public class NodeList<E> {
    class Cursor { } // type declaration is a standard type
    {
        NodeList.Cursor cursor; // NodeList.Cursor is raw!
        NodeList<String>.Cursor c2; // NodeList<String>.Cursor is standard type
    }
}

TTypes currently assume that the type declaration of a raw type is a generic
type, which is not the case here. I think that's against the current spec:
    For parameterized types and raw types, getTypeDeclaration() returns the
    binding for the corresponding generic type.

We have to sort out whether the spec or the implementation should be corrected.
Comment 4 Markus Keller CLA 2006-07-03 09:23:23 EDT
*** Bug 134761 has been marked as a duplicate of this bug. ***
Comment 5 Markus Keller CLA 2006-07-04 05:45:45 EDT
Fixed CCE in HEAD.

Treating non-generic member type of generic type like other non-generic types for now. Opened bug 149541 for the full fix.