Community
Participate
Working Groups
20021018 When building an AST from the following code, an IllegalArgumentException is thrown. (note that there are syntax errors in the code) public class A { public static void collectCorrections() { processors= null; } try { int id= 2; } catch (CoreException e) { } } } java.lang.IllegalArgumentException at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java (Compiled Code)) at org.eclipse.jdt.core.dom.ASTConverter.checkAndAddMultipleFieldDeclaration (ASTConverter.java:246) at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations (ASTConverter.java:224) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:169) at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:69) at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:241) at org.eclipse.jdt.internal.ui.text.correction.UnresolvedElementsSubProcessor.getVa riableProposals(UnresolvedElementsSubProcessor.java:43) at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.collectCorre ctions(JavaCorrectionProcessor.java:216) at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.processProbl emAnnotations(JavaCorrectionProcessor.java:169) at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.computeCompl etionProposals(JavaCorrectionProcessor.java:141) at org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals (ContentAssistant.java:1279) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals (CompletionProposalPopup.java:177) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$7 (CompletionProposalPopup.java:176) at org.eclipse.jface.text.contentassist.CompletionProposalPopup$3.run (CompletionProposalPopup.java:138) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java (Compiled Code)) at org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals (CompletionProposalPopup.java:133) at org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions (ContentAssistant.java:1199) at org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionSourceViewer.doOperati on(JavaCorrectionSourceViewer.java:47) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer .doOperation(CompilationUnitEditor.java:237) at org.eclipse.ui.texteditor.TextOperationAction$1.run (TextOperationAction.java:119) at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java (Compiled Code)) at org.eclipse.ui.texteditor.TextOperationAction.run (TextOperationAction.java:117) at org.eclipse.ui.internal.WWinKeyBindingService.invoke (WWinKeyBindingService.java:134) at org.eclipse.ui.internal.WWinKeyBindingService.pressed (WWinKeyBindingService.java:109) at org.eclipse.ui.internal.WWinKeyBindingService$5.widgetSelected (WWinKeyBindingService.java:325) at org.eclipse.ui.internal.AcceleratorMenu$2.handleEvent (AcceleratorMenu.java:53) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java (Compiled Code)) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java (Compiled Code)) at org.eclipse.ui.internal.Workbench.run(Workbench.java:1403) at org.eclipse.core.internal.boot.InternalBootLoader.run (InternalBootLoader.java:775) at org.eclipse.core.boot.BootLoader.run(BootLoader.java:462) at java.lang.reflect.Method.invoke(Native Method) at org.eclipse.core.launcher.Main.basicRun(Main.java:247) at org.eclipse.core.launcher.Main.run(Main.java:703) at org.eclipse.core.launcher.Main.main(Main.java:539)
This sounds like positions unset in case of a syntax error. I will investigate.
It is a bug in the closing position for an initializer. The recovery is not closing the first initializer from this code: try { int id= 2; } catch (CoreException e) { } This is converted into three fields: 1) an initializer { int id = 2; } 2) a field (CoreException e) 3) An initializer {} The first initializer doesn't contain valid positions. I need to investigate why it is not closed on the first closing brace ('}' in front of the catch. Note that the resulting tree is completely wrong. It does not match the source at all for everything after the first method.
This is a bug in the recovery. The int id = 2; resets the current element to the recovery type and then the recovery initializer is never closed properly. Removing this line int id = 2; fixes the problem. Need to investigate why the int id = 2; is considered as a field declaration without first closing the block inside the recovered initializer. I would expect int id = 2; to be treated as a local variable declaration inside the initializer and not a field declaration.
Fixed and released in 2.1 stream. The bug was in the recovery.