Community
Participate
Working Groups
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)
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.
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.
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
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.
David, I added regression tests in ASTConverterTest2.
Fix seems good for me Fixed.
Verified in I20040506-0200
Verified in 200405180816