Bug 218824

Summary: [DOM/AST] incorrect code leads to IllegalArgumentException during AST creation
Product: [Eclipse Project] JDT Reporter: Olivier Thomann <Olivier_Thomann>
Component: CoreAssignee: David Audel <david_audel>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: jerome_lanneluc
Version: 3.4   
Target Milestone: 3.4 M6   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed patch none

Description Olivier Thomann CLA 2008-02-13 12:31:46 EST
Using 3.4M5, copy/paste the following code into a java editor:

public class A {
	public void takeParam(int i) {
		// do something
	}

	void test() {
		char c = 'a';
		   public void takeParam(int i) {
			     // do something
			   }

			   void test() {
			     char c = 'a';
			    takeParam((int) c);
			   }takeParam((int) c);
	}
}

I got it by doing a paste operation at the wrong location.

On the next reconcile, an IAE is thrown.

java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:2611)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:493)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:317)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2297)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1549)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2491)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:522)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:178)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2676)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1260)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:256)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:894)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:653)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider$1.run(ASTProvider.java:540)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:533)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:474)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:462)
	at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:126)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:168)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:153)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

The problem must be due to invalid positions inside the recovery.
Comment 1 David Audel CLA 2008-03-19 05:34:47 EDT
Created attachment 92877 [details]
Proposed patch
Comment 2 David Audel CLA 2008-03-19 05:39:50 EDT
Released for 3.4M6.

Test added
  ASTConverterBugsTest#testBug218824a()

During recovery the declarationSourceEnd of a method declaration was not set when this method had no body.
Comment 3 Jerome Lanneluc CLA 2008-03-25 11:12:35 EDT
Verified for 3.4M6 using I20080325-0100