Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343691 - exception stack trace on $ as a type name
Summary: exception stack trace on $ as a type name
Status: RESOLVED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: 3.3   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 3.2.4   Edit
Assignee: Chris Jaun CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard: PMC_approved
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-23 14:40 EDT by Philippe Marschall CLA
Modified: 2011-04-28 22:01 EDT (History)
3 users (show)

See Also:
david_williams: pmc_approved+
cmjaun: pmc_approved? (raghunathan.srinivasan)
cmjaun: pmc_approved? (naci.dai)
cmjaun: pmc_approved? (deboer)
cmjaun: pmc_approved? (neil.hauge)
cmjaun: pmc_approved? (kaloyan)
cbridgha: pmc_approved+
thatnitind: review+


Attachments
sample library file to reproduce the issue (435 bytes, text/plain)
2011-04-23 14:41 EDT, Philippe Marschall CLA
no flags Details
the same without dollar and everything works (450 bytes, text/plain)
2011-04-23 14:42 EDT, Philippe Marschall CLA
no flags Details
patch (5.33 KB, patch)
2011-04-26 14:19 EDT, Chris Jaun CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Marschall CLA 2011-04-23 14:40:05 EDT
JavaScript allows $ as an identifier and at least two JavaScript libraries actually make use of this. However JSDT doesn't seem to handle this is every case and the stack trace below shows up in the console.

Steps to reproduce:
1. Create a JavaScript project
2. Add the attached dollar-bug.js as a JavaScript library
3. Type the following in a JavaScript file in this project
 $.hasData(null)
4. open the 'Documentation' view
5. place the cursor in the middle of 'hasData'
6. The documentation for hasData should appear in the 'Documentation' view and the stack trace below should appear in the console. (Not the 'Error Log', I had to run JSDT as an Eclipse application from within Eclipse to see it)

On comparison everything seems to work fine if $ is substituted for 'jQuery'. See the attached no-dollar.js and try jQuery.hasData(null)


Exception Stack Trace

org.eclipse.swt.SWTException: Failed to execute runnable (java.lang.ArrayIndexOutOfBoundsException: 0)
	at org.eclipse.swt.SWT.error(SWT.java:4277)
	at org.eclipse.swt.SWT.error(SWT.java:4192)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:137)
	at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:3924)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3601)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2696)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2660)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2494)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:674)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:667)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	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:344)
	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:622)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
	at org.eclipse.wst.jsdt.internal.core.util.BindingKeyParser.parseInnerType(BindingKeyParser.java:668)
	at org.eclipse.wst.jsdt.internal.core.util.BindingKeyParser.parse(BindingKeyParser.java:548)
	at org.eclipse.wst.jsdt.internal.core.util.BindingKeyParser.parse(BindingKeyParser.java:529)
	at org.eclipse.wst.jsdt.core.BindingKey.toSignature(BindingKey.java:98)
	at org.eclipse.wst.jsdt.ui.JavaScriptElementLabels.getMethodLabel(JavaScriptElementLabels.java:478)
	at org.eclipse.wst.jsdt.ui.JavaScriptElementLabels.getElementLabel(JavaScriptElementLabels.java:425)
	at org.eclipse.wst.jsdt.ui.JavaScriptElementLabels.getElementLabel(JavaScriptElementLabels.java:402)
	at org.eclipse.wst.jsdt.internal.ui.infoviews.AbstractInfoView.doSetInput(AbstractInfoView.java:569)
	at org.eclipse.wst.jsdt.internal.ui.infoviews.AbstractInfoView.access$2(AbstractInfoView.java:556)
	at org.eclipse.wst.jsdt.internal.ui.infoviews.AbstractInfoView$3.run(AbstractInfoView.java:545)
	at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
	at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:134)
	... 23 more
Comment 1 Philippe Marschall CLA 2011-04-23 14:41:13 EDT
Created attachment 193958 [details]
sample library file to reproduce the issue
Comment 2 Philippe Marschall CLA 2011-04-23 14:42:00 EDT
Created attachment 193959 [details]
the same without dollar and everything works
Comment 3 Chris Jaun CLA 2011-04-26 14:19:13 EDT
Created attachment 194085 [details]
patch
Comment 4 Chris Jaun CLA 2011-04-26 14:40:20 EDT
    Explain why you believe this is a stop-ship defect. Or, if it is a "hotbug" (requested by an adopter) please document it as such. 

Many JavaScript libraries use the $ as type names, jquery being one of the most prominent. We should not be throwing exceptions on $ type names.

    Is there a work-around? If so, why do you believe the work-around is insufficient? 

No.

    How has the fix been tested? Is there a test case attached to the bugzilla record? Has a JUnit Test been added? 

Updated our InferTypesTest to have examples with $ in the type names. It has also been tested manually in content assist and hover help scenarios.

    Give a brief technical overview. Who has reviewed this fix? 

In JDT a $ had been used as a special character in type signatures to represent inner types. We don't have inner types in JSDT and made updates to treat $ as a normal character in signatures.

    What is the risk associated with this fix? 

It is possible there is still some code that expects $ to be a special character, but testing so far has not revealed any problems.
Comment 5 Chris Jaun CLA 2011-04-27 17:38:04 EDT
Checked into 3.2.4.
Comment 6 Chris Jaun CLA 2011-04-27 17:53:55 EDT
Checked into HEAD.
Comment 7 Philippe Marschall CLA 2011-04-28 03:50:16 EDT
Thanks for fixing so quickly.