Bug 12454

Summary: AST/DOM: IllegalArgumentException generated by bad source
Product: [Eclipse Project] JDT Reporter: Jared Burns <jared_burns>
Component: CoreAssignee: Philipe Mulet <philippe_mulet>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse
Version: 2.0   
Target Milestone: 2.0 M5   
Hardware: Other   
OS: other   
Whiteboard:

Description Jared Burns CLA 2002-03-28 12:03:44 EST
The following source (yes, it's bad) generates an IllegalArgumentException when
we try to parse it.

void ___eval() {
new Runnable(){
void ___run() throws Throwable {
return blah;
}
private String blarg;
public void run (){
}
}
;}
public class Hello{
private static int x;
private String blah;
public static void main (String[] args){
}
public void hello (){
}
public boolean blah (){
return false;}
public void foo (){
}
}

Here's the relevant part of the stack trace:

java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.SimpleName.setIdentifier(SimpleName.java:129)
	at org.eclipse.jdt.core.dom.AST.newSimpleName(AST.java:463)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:137)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:73)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:330)
Comment 1 Olivier Thomann CLA 2002-03-28 12:23:41 EST
What do you expect? You don't even provide a compilation unit source. 
Comment 2 Jared Burns CLA 2002-03-28 13:07:20 EST
We don't expect a valid AST (the bad source was clearly from a bug), but the
method shouldn't blow up.
Comment 3 Olivier Thomann CLA 2002-03-28 14:23:56 EST
In fact this is a bug in the error recovery. The compilation unit declaration is 
returned with two types. One anonymous class and one class. An anonymous class 
cannot be a toplevel type. This doesn't work. I am expecting the beginning of 
the code to be ignore till the declaration of the class Hello.
The converter blew up trying to set the name of the anonymous type declaration.
Comment 4 Philipe Mulet CLA 2002-04-02 05:36:20 EST
Fixed recovery to filter out anonymous toplevel types during the updating 
phase. Regression test (DietRecoveryTest#test102) added.

Fixed.