Bug 15061

Summary: IllegalArgumentException in ASTNode.setSourceRange
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Tod_Creasey
Version: 2.0   
Target Milestone: 2.0 M6   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Martin Aeschlimann CLA 2002-05-02 04:26:59 EDT
20020501

If you build an AST on this code (containing errors), an 
IllegalArgumentException is thrown.

To reproduce: Select 'z' and do 'Surround with try/catch'

Note
- The inner interface is required
- Theres an opening bracket in the method

public class A {
	public static interface X {
		int doQuery(boolean x);
	}

	public void setX(boolean x) {
		 {
		z
	}
}

java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:1459)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:633)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations
(ASTConverter.java:228)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:492)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations
(ASTConverter.java:233)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:168)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:73)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:373)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:246)
	at 
org.eclipse.jdt.internal.ui.text.correction.LocalCorrectionsSubProcessor.addCast
Proposals(LocalCorrectionsSubProcessor.java:48)
	at 
org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.collectCorre
ctions(JavaCorrectionProcessor.java:190)
	at 
org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor.computeCompl
etionProposals(JavaCorrectionProcessor.java:127)
	at 
org.eclipse.jface.text.contentassist.ContentAssistant.computeCompletionProposals
(ContentAssistant.java:1205)
	at 
org.eclipse.jface.text.contentassist.CompletionProposalPopup.computeProposals
(CompletionProposalPopup.java:104)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup.access$3
(CompletionProposalPopup.java:103)
	at org.eclipse.jface.text.contentassist.CompletionProposalPopup$1.run
(CompletionProposalPopup.java:72)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:56)
	at 
org.eclipse.jface.text.contentassist.CompletionProposalPopup.showProposals
(CompletionProposalPopup.java:67)
	at 
org.eclipse.jface.text.contentassist.ContentAssistant.showPossibleCompletions
(ContentAssistant.java:1140)
	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:219)
	at org.eclipse.ui.texteditor.TextOperationAction.run
(TextOperationAction.java:88)
	at org.eclipse.ui.texteditor.RetargetTextEditorAction.run
(RetargetTextEditorAction.java:103)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:590)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection
(ActionContributionItem.java:407)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent
(ActionContributionItem.java:361)
	at org.eclipse.jface.action.ActionContributionItem.access$0
(ActionContributionItem.java:352)
	at 
org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent
(ActionContributionItem.java:47)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java
(Compiled Code))
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.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:866)
	at org.eclipse.core.internal.boot.InternalBootLoader.run
(InternalBootLoader.java:733)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:349)
	at java.lang.reflect.Method.invoke(Native Method)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:162)
	at org.eclipse.core.launcher.Main.run(Main.java:588)
	at org.eclipse.core.launcher.UIMain.main(UIMain.java:52)
Comment 1 Olivier Thomann CLA 2002-05-02 10:46:08 EDT
The bodyEnd field of the AbstractMethodDeclaration doQuery was not set properly.
Comment 2 Olivier Thomann CLA 2002-05-02 11:10:09 EDT
Fixed and released in HEAD. In your example, the source end of the method setX and the source end of 
the type A are the same due to the missing brace.
Comment 3 Olivier Thomann CLA 2002-05-02 12:05:18 EDT
Now this doesn't fail anymore, but you cannot surround 'z' with try/catch. It 
reports that the selection doesn't cover a set of statements.
Comment 4 Olivier Thomann CLA 2002-05-02 12:06:04 EDT
*** Bug 15107 has been marked as a duplicate of this bug. ***
Comment 5 Martin Aeschlimann CLA 2002-05-02 12:29:01 EDT
sure, of course. this was just an example that created an AST that crashes.