Bug 274898 - [recovery] IllegalArgumentException in ASTNode#setSourceRange()
Summary: [recovery] IllegalArgumentException in ASTNode#setSourceRange()
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4.2   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.5.1   Edit
Assignee: David Audel CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 248246 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-05-04 17:27 EDT by Tobias Gierke CLA
Modified: 2009-08-27 14:53 EDT (History)
7 users (show)

See Also:


Attachments
Proposed patch (3.73 KB, patch)
2009-06-02 06:03 EDT, David Audel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Gierke CLA 2009-05-04 17:27:34 EDT
Creating a new .java file with just the following contents and trying to automatically add the missing import statements ( Source -> Add import ) triggers an IAE that causes an error dialog "AST cannot be null" to show. 

--------------- CODE -----------------

public class Test {
	
	public Test() {

		final anClass labelModel =
			new new SomeOtherClass() {
			
		};
		
	}
}

------------ Stacktrace ------------

------------ Exception #2 ----------

java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:477)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
	at org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:758)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:755)
	at org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2487)
	at org.eclipse.ui.internal.progress.ProgressManager$5.run(ProgressManager.java:1217)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.internal.progress.ProgressManager.runInUI(ProgressManager.java:1210)
	at org.eclipse.jdt.internal.ui.javaeditor.AddImportOnSelectionAction.run(AddImportOnSelectionAction.java:136)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
	at org.eclipse.ui.commands.ActionHandler.execute(ActionHandler.java:185)
	at org.eclipse.ui.internal.handlers.LegacyHandlerWrapper.execute(LegacyHandlerWrapper.java:109)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:508)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:169)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:472)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:824)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:882)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:571)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:512)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:127)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1436)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1157)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1182)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1167)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1194)
	at org.eclipse.swt.widgets.Widget.gtk_key_press_event(Widget.java:698)
	at org.eclipse.swt.widgets.Control.gtk_key_press_event(Control.java:2765)
	at org.eclipse.swt.widgets.Composite.gtk_key_press_event(Composite.java:702)
	at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1543)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4506)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4099)
	at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method)
	at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:5792)
	at org.eclipse.swt.widgets.Display.eventProc(Display.java:1177)
	at org.eclipse.swt.internal.gtk.OS._g_main_context_iteration(Native Method)
	at org.eclipse.swt.internal.gtk.OS.g_main_context_iteration(OS.java:1550)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3031)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2384)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2348)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2200)
	at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:495)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:490)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:386)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:549)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:504)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1236)
Caused by: java.lang.IllegalArgumentException: AST must not be null
	at org.eclipse.jdt.core.dom.rewrite.ImportRewrite.create(ImportRewrite.java:185)
	at org.eclipse.jdt.ui.CodeStyleConfiguration.createImportRewrite(CodeStyleConfiguration.java:70)
	at org.eclipse.jdt.internal.corext.codemanipulation.StubUtility.createImportRewrite(StubUtility.java:1527)
	at org.eclipse.jdt.internal.corext.codemanipulation.AddImportsOperation.run(AddImportsOperation.java:165)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:716)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4563)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:92)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
	... 59 more


------------ Exception #1 ----------


java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:2611)
	at org.eclipse.jdt.core.dom.ASTConverter.convertToVariableDeclarationStatement(ASTConverter.java:3076)
	at org.eclipse.jdt.core.dom.ASTConverter.checkAndAddMultipleLocalDeclaration(ASTConverter.java:396)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:521)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations(ASTConverter.java:179)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:2692)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:1262)
	at org.eclipse.jdt.core.dom.CompilationUnitResolver.convert(CompilationUnitResolver.java:256)
	at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser.java:905)
	at org.eclipse.jdt.core.dom.ASTParser.createAST(ASTParser.java:656)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider$1.run(ASTProvider.java:540)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.createAST(ASTProvider.java:533)
	at org.eclipse.jdt.internal.ui.javaeditor.ASTProvider.getAST(ASTProvider.java:474)
	at org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:129)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartListenerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:168)
	at org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$3.run(SelectionListenerWithASTManager.java:153)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

------------ Eclipse details ------------

Ganymede 3.4.2 JEE / Linux 32 bit

eclipse.buildId=M20090211-1700
java.version=1.6.0_13
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US
Command-line arguments:  -os linux -ws gtk -arch x86
Comment 1 Tobias Gierke CLA 2009-05-04 17:29:43 EDT
Exception #2 triggers the error dialog but Exception #1 seems to be the root cause
Comment 2 David Williams CLA 2009-05-15 02:16:47 EDT
Apologies for the late triage, but believe this belongs in JDT. 
And hopefully is no longer a problem? 
Comment 3 Dani Megert CLA 2009-05-15 02:56:03 EDT
Can reproduce using I20090514-2000.

Note that the given sample code is completely broken.
Comment 4 Tobias Gierke CLA 2009-05-15 08:03:08 EDT
(In reply to comment #3)
> Can reproduce using I20090514-2000.
> 
> Note that the given sample code is completely broken.

Yes, should've probably pointed this out. One gets the same exception when using ean xisting type like so:

------- SNIP --------
import javax.swing.event.TreeModelListener;

public class Test {
   public Test() {		
      TreeModelListener listener = new new TreeModelListener() {};
   }
}
------- SNIP ------

The problem seems to be caused by the "new new <TYPE>".

Anyway, I'd much rather have a "your code is completely broken" exception than just some arbitrary NPE ;-)

Regards,

Tobias
Comment 5 David Audel CLA 2009-05-26 04:07:23 EDT
Two bugs appear with this test case.

There is a conflicts between 'normal' and 'statements' recovery which cause the failure of the statements recovery and bug in 'normal' recovery which cause the exception ('declarationSourceStart' of the anonymous type is not computed)

I entered a separate bug for the conflict problem (bug 277805).
Comment 6 David Audel CLA 2009-06-02 06:03:34 EDT
Created attachment 137976 [details]
Proposed patch

Patch for the 'declarationSourceStart' problem.
Comment 7 David Audel CLA 2009-06-18 04:17:24 EDT
Released for 3.6M1.

Tests added
   ASTConverterBugsTest#testBug274898a() -> testBug274898b()
Comment 8 David Audel CLA 2009-06-18 07:08:42 EDT
Olivier,

The bug cause an exception and the fix is a one line change.
It could be a good candidate for 3.5.1.
What do you think?
Comment 9 Olivier Thomann CLA 2009-06-18 09:27:41 EDT
Fix is safe.
+1 for 3.5.1.
Comment 10 David Audel CLA 2009-06-19 03:43:41 EDT
Released for 3.5.1.

Tests added
   ASTConverterBugsTest#testBug274898a() -> testBug274898b()
Comment 11 David Audel CLA 2009-06-25 05:25:50 EDT
*** Bug 248246 has been marked as a duplicate of this bug. ***
Comment 12 Jay Arthanareeswaran CLA 2009-08-04 01:20:55 EDT
Verified for 3.6M1 using I20090802-2000
Comment 13 Kent Johnson CLA 2009-08-27 14:53:47 EDT
Verified for 3.5.1 using build M20090826-1100