Bug 48502 - Exception during "Java AST creation"
Summary: Exception during "Java AST creation"
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-12-11 11:49 EST by Markus Keller CLA
Modified: 2004-05-18 11:15 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Keller CLA 2003-12-11 11:49:30 EST
I20031209, and also with jdt.core from HEAD:

public class Example
{
	public Example() {	}
	// <- insert '{' before comment
	public static void main(String[] args) { }
}

After inserting the opening brace, the log fills with:

Error Dec 11, 2003 17:42:24.253 An internal error occurred during: "Java AST
creation".
java.lang.IllegalArgumentException
at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:1486)
at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1779)
at
org.eclipse.jdt.core.dom.ASTConverter.checkAndAddMultipleFieldDeclaration(ASTConverter.java:257)
at
org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:237)
at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:182)
at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:80)
at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:354)
at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:247)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.computeAST(SelectionListenerWithASTManager.java:106)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:116)
at
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$1.run(SelectionListenerWithASTManager.java:92)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:62)
Comment 1 Olivier Thomann CLA 2004-01-05 12:22:15 EST
The bug is in the recovery.
The source positions for the initializer are wrong. It ends before it starts!
Therefore the positions of the DOM/AST initializer are invalid. And this leads
to the exception seen in the stack trace.

See:
In RecoveredInitializer:
/*
 * Update the declarationSourceEnd of the corresponding parse node
 */
public void updateSourceEndIfNecessary(int braceStart, int braceEnd){
	if (this.fieldDeclaration.declarationSourceEnd == 0) {
		Initializer initializer = (Initializer)fieldDeclaration;
		if(parser().rBraceSuccessorStart >= braceEnd) {
			initializer.declarationSourceEnd = parser().rBraceEnd;
			initializer.bodyEnd = parser().rBraceStart;
		} else {
			initializer.declarationSourceEnd = braceEnd;
			initializer.bodyEnd  = braceStart - 1;
		}
		if(initializer.block != null) {
			initializer.block.sourceEnd = initializer.declarationSourceEnd;
		}
	}
}

The sender is calling this method with:
updateSourceEndIfNecessary(sourceEnd + 1, sourceEnd).

This means we have a start after the end.

David, could you please comment?

Thanks.
Comment 2 Rob Grzywinski CLA 2004-02-23 16:22:14 EST
Eclipse 3.0M7 (XP):

public class Something
{
    public void broken(}
{}

    public void thereMustSomethingHere()
    {}
}

If I save after the "{}"'s after "broken(}" (notice that that's not a right 
paren) then I get:

!ENTRY org.eclipse.core.runtime 4 2 Feb 23, 2004 13:02:55.250
!MESSAGE An internal error occurred during: "Java AST creation".
!STACK 0
java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:1542)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1889)
	at 
org.eclipse.jdt.core.dom.ASTConverter.checkAndAddMultipleFieldDeclaration
(ASTConverter.java:357)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations
(ASTConverter.java:334)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:278)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:142)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:965)
	at 
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup.computeAST(SelectionListenerWithASTManager.java:125)
	at 
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:144)
	at 
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$1.run
(SelectionListenerWithASTManager.java:99)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:62)

If "broken(}" is the last element in the file then this will not occur.
Comment 3 Travis Hume CLA 2004-03-15 13:02:56 EST
linux gtk+
Version: 3.0.0
Build id: 200403100800

I've seen this a couple times now.  Seems easy to recreate:
1. format a large file 500+ lines
2. undo
Comment 4 Olivier Thomann CLA 2004-04-30 15:55:33 EDT
Looking for a fix for bug 60581, I patch this problem.
Could you please double-check it?

Change in:
RecoveredInitializer#updateSourceEndIfNecessary(int, int)

I check that the bodyStart is not greater than the value we want to set for the
declarationSourceEnd and declarationEnd.
Comment 5 Olivier Thomann CLA 2004-04-30 15:58:30 EDT
David, I added regression tests in ASTConverterTest2.
Comment 6 David Audel CLA 2004-05-04 05:36:28 EDT
Fix seems good for me

Fixed.
Comment 7 Markus Keller CLA 2004-05-07 15:17:42 EDT
Verified in I20040506-0200
Comment 8 Olivier Thomann CLA 2004-05-18 11:15:01 EDT
Verified in 200405180816