Bug 25124 - AST: IllegalArgumentException on creation
Summary: AST: IllegalArgumentException on creation
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.1 M2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-21 11:04 EDT by Martin Aeschlimann CLA
Modified: 2002-11-25 09:07 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2002-10-21 11:04:02 EDT
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)
Comment 1 Olivier Thomann CLA 2002-10-21 11:10:30 EDT
This sounds like positions unset in case of a syntax error. I will investigate.
Comment 2 Olivier Thomann CLA 2002-10-21 11:29:49 EDT
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.
Comment 3 Olivier Thomann CLA 2002-10-21 12:35:41 EDT
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.
Comment 4 Olivier Thomann CLA 2002-10-22 09:14:00 EDT
Fixed and released in 2.1 stream.
The bug was in the recovery.