Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 419748

Summary: [1.8][dom ast] MethodDeclaration's receiverType cannot be AnnotatableType
Product: [Eclipse Project] JDT Reporter: Markus Keller <markus.kell.r>
Component: CoreAssignee: Markus Keller <markus.kell.r>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r, srikanth_sankaran
Version: 4.3   
Target Milestone: BETA J8   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Markus Keller CLA 2013-10-17 13:09:18 EDT
MethodDeclaration's receiverType cannot be an AnnotatableType, since ParameterizedType is not an AnnotatableType. Example:


package jsr335.invalid;

public class C {
    class A<T> {
        class Inner {
             public Inner(A<T> A.this) { }
        }
    }
}

java.lang.ClassCastException: org.eclipse.jdt.core.dom.ParameterizedType cannot be cast to org.eclipse.jdt.core.dom.AnnotatableType
	at org.eclipse.jdt.core.dom.ASTConverter.convertAndSetReceiver(ASTConverter.java:888)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:543)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:201)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2956)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:206)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2956)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:206)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2956)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1374)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:295)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:1212)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:812)
Comment 1 Markus Keller CLA 2013-10-17 13:30:24 EDT
Fixed the wrong type in the API with http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=6c3b6971f88c7f6d5be3c70fdaf936700dc7f94b

I've added ASTConverter18Test#testParameterizedReceiverType(), but I had to release it in an incomplete version since the source range of the outermost ParameterizedType doesn't include the annotation. See the commented
//TODO: bad AST node structure:
for the remaining work to be done for this bug.
Comment 2 Srikanth Sankaran CLA 2013-10-17 18:57:56 EDT
(In reply to Markus Keller from comment #1)
> Fixed the wrong type in the API with
> http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/
> ?id=6c3b6971f88c7f6d5be3c70fdaf936700dc7f94b


Markus, this still leaves org.eclipse.jdt.core.dom.MethodDeclaration.RECEIVER_TYPE_PROPERTY referring
to AnnotatableType - is this intentional ? 

and a few casts in:
org.eclipse.jdt.core.dom.MethodDeclaration.internalGetSetChildProperty(ChildPropertyDescriptor, boolean, ASTNode)

org.eclipse.jdt.core.dom.MethodDeclaration.clone0(AST)


org.eclipse.jdt.core.dom.AnnotatableType

etc.

Would org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.rewriteModifiers2(ASTNode, ChildListPropertyDescriptor, int)

hit a CCE for public Inner(final A<T> A.this) ? I didn't check.
Comment 3 Markus Keller CLA 2013-10-21 09:53:19 EDT
(In reply to Srikanth Sankaran from comment #2)
> Markus, this still leaves
> org.eclipse.jdt.core.dom.MethodDeclaration.* referring
> to AnnotatableType - is this intentional ?

Not intended. All occurrences of "AnnotatableType" in MethodDeclaration should be replaced by "Type" (textual Replace All).


> Would
> org.eclipse.jdt.internal.core.dom.rewrite.ASTRewriteAnalyzer.
> rewriteModifiers2(ASTNode, ChildListPropertyDescriptor, int)
> 
> hit a CCE for public Inner(final A<T> A.this) ? I didn't check.

I don't see a possibility for a CCE there; the cast is always protected by the preceding instanceof. But the current DOM API actually misses support for modifiers on the receiver parameter. Filed bug 419974.
Comment 4 Srikanth Sankaran CLA 2013-10-22 07:19:31 EDT
(In reply to Markus Keller from comment #3)
> (In reply to Srikanth Sankaran from comment #2)
> > Markus, this still leaves
> > org.eclipse.jdt.core.dom.MethodDeclaration.* referring
> > to AnnotatableType - is this intentional ?
> 
> Not intended. All occurrences of "AnnotatableType" in MethodDeclaration
> should be replaced by "Type" (textual Replace All).

Thanks, Released here: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?h=BETA_JAVA8&id=56279d048bf630d57d8fac349861b864730cf774

> I don't see a possibility for a CCE there; the cast is always protected by
> the preceding instanceof. 

Correct. Thanks.
Comment 5 Markus Keller CLA 2013-10-23 13:42:55 EDT
Thanks Srikanth, I think we can close this bug now.

(In reply to Markus Keller from comment #1)
> I've added ASTConverter18Test#testParameterizedReceiverType(), but I had to
> release it in an incomplete version since the source range of the outermost
> ParameterizedType doesn't include the annotation.

Let's take this over to bug 419974: http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=85e8ac1cb08d7a07857723eab3efc805d5dbc4ea