Bug 72458 - ASTConverter error when parsing assert statements containing parenthesis
Summary: ASTConverter error when parsing assert statements containing parenthesis
Status: RESOLVED DUPLICATE of bug 38732
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-23 14:38 EDT by Felix Berger CLA
Modified: 2004-08-23 15:58 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Felix Berger CLA 2004-08-23 14:38:58 EDT
a call of AST.parseCompilationUnit() on code like this

public class TestClass
{
  public void demoMethod(Object obj)
  {
    assert(obj != null);
  }
}

in a custom plug in lleads to the following exception:

!ENTRY org.eclipse.ui 4 4 Aug 23, 2004 14:44:58.411
!MESSAGE Unhandled exception caught in event loop.
!ENTRY org.eclipse.ui 4 0 Aug 23, 2004 14:44:58.411
!MESSAGE java.lang.reflect.InvocationTargetException
!STACK 0
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at glance.af.tools.header.popup.actions.AddHeaderAndCVSIdAction.run
(AddHeaderAndCVSIdAction.java:103)
	at org.eclipse.ui.internal.PluginAction.runWithEvent
(PluginAction.java:251)
	at 
org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection
(ActionContributionItem.java:456)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetEvent
(ActionContributionItem.java:403)
	at org.eclipse.jface.action.ActionContributionItem.access$0
(ActionContributionItem.java:397)
	at 
org.eclipse.jface.action.ActionContributionItem$ActionListener.handleEvent
(ActionContributionItem.java:72)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:81)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:840)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2022)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:1729)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1402)
	at org.eclipse.ui.internal.Workbench.run(Workbench.java:1385)
	at org.eclipse.core.internal.boot.InternalBootLoader.run
(InternalBootLoader.java:858)
	at org.eclipse.core.boot.BootLoader.run(BootLoader.java:461)
	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:324)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:291)
	at org.eclipse.core.launcher.Main.run(Main.java:747)
	at org.eclipse.core.launcher.Main.main(Main.java:583)
Caused by: java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:313)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:252)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run
(ProgressMonitorDialog.java:357)
	at glance.af.tools.header.popup.actions.AddHeaderAndCVSIdAction.run
(AddHeaderAndCVSIdAction.java:99)
	... 20 more
Caused by: java.lang.IllegalArgumentException
	at org.eclipse.jdt.core.dom.ASTNode.setSourceRange(ASTNode.java:1469)
	at org.eclipse.jdt.core.dom.ASTConverter.convert
(ASTConverter.java:1801)
	at org.eclipse.jdt.core.dom.ASTConverter.convert
(ASTConverter.java:1708)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:719)
	at org.eclipse.jdt.core.dom.ASTConverter.buildBodyDeclarations
(ASTConverter.java:242)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:181)
	at org.eclipse.jdt.core.dom.ASTConverter.convert(ASTConverter.java:79)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:540)
	at org.eclipse.jdt.core.dom.AST.parseCompilationUnit(AST.java:277)
	at 
glance.af.tools.header.popup.actions.AddHeaderAndCVSIdAction.handleCompilationU
nit(AddHeaderAndCVSIdAction.java:205)
	at 
glance.af.tools.header.popup.actions.AddHeaderAndCVSIdAction.handeJavaElement
(AddHeaderAndCVSIdAction.java:112)
	at glance.af.tools.header.popup.actions.AddHeaderAndCVSIdAction.run
(AddHeaderAndCVSIdAction.java:252)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:302)
	... 23 more

our research shows the following:
- it only happens, when the assert-expression contains parenthesis
- the reason is, that the starting position for the call to 
  ASTConverter.retrieveEndingSemiColonPosition() in
  ASTConverter.convert(AssertStatement) is like this:

      assert(obj != null );
                        ^
  Because of this, the method is unable to balance the parenthesis
  correctly and returns -1 as a result. This later on leads to a
  IllegalArgumentException in ASTNode.setSourceRange().
Comment 1 Olivier Thomann CLA 2004-08-23 15:55:36 EDT
This is a known bug that has been fixed in 3.0.
Comment 2 Olivier Thomann CLA 2004-08-23 15:58:47 EDT

*** This bug has been marked as a duplicate of 38732 ***