Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334282 - [formatter] Formatting Javascript throws ArrayIndexOutOfBoundsException
Summary: [formatter] Formatting Javascript throws ArrayIndexOutOfBoundsException
Status: RESOLVED FIXED
Alias: None
Product: JSDT
Classification: WebTools
Component: General (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.2.5   Edit
Assignee: Chris Jaun CLA
QA Contact: Nitin Dahyabhai CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-13 11:40 EST by Florian Lasinger CLA
Modified: 2011-07-14 02:31 EDT (History)
2 users (show)

See Also:
thatnitind: review+


Attachments
Javascript Testcase - formatting fails (774 bytes, text/plain)
2011-01-13 11:41 EST, Florian Lasinger CLA
no flags Details
patch (1.54 KB, patch)
2011-06-29 14:27 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 Florian Lasinger CLA 2011-01-13 11:40:01 EST
Build Identifier: 20100917-0705

Formatting the file in the attachment gives the following message:
"Format" did not complete normally.  Please see the log for more information.
java.lang.ArrayIndexOutOfBoundsException


!ENTRY org.eclipse.ui 4 0 2011-01-13 17:36:51.339
!MESSAGE java.lang.ArrayIndexOutOfBoundsException
!STACK 0
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at org.eclipse.wst.jsdt.internal.compiler.parser.Scanner.getRawTokenSource(Scanner.java:493)
	at org.eclipse.wst.jsdt.internal.formatter.Scribe.printNextToken(Scribe.java:1399)
	at org.eclipse.wst.jsdt.internal.formatter.Scribe.printNextToken(Scribe.java:1392)
	at org.eclipse.wst.jsdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:3885)
	at org.eclipse.wst.jsdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:180)
	at org.eclipse.wst.jsdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatterVisitor.java:2781)
	at org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:555)
	at org.eclipse.wst.jsdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:545)
	at org.eclipse.wst.jsdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:779)
	at org.eclipse.wst.jsdt.internal.formatter.DefaultCodeFormatter.formatCompilationUnit(DefaultCodeFormatter.java:237)
	at org.eclipse.wst.jsdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:155)
	at org.eclipse.wst.jsdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatterUtil.java:235)
	at org.eclipse.wst.jsdt.internal.ui.text.java.JavaFormattingStrategy.format(JavaFormattingStrategy.java:61)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatMaster(MultiPassContentFormatter.java:193)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.format(MultiPassContentFormatter.java:142)
	at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:966)
	at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1534)
	at org.eclipse.wst.jsdt.internal.ui.javaeditor.JavaSourceViewer.doOperation(JavaSourceViewer.java:172)
	at org.eclipse.wst.jsdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:185)
	at org.eclipse.ui.texteditor.TextOperationAction$1.run(TextOperationAction.java:131)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	at org.eclipse.ui.texteditor.TextOperationAction.run(TextOperationAction.java:129)
	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:468)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:786)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:885)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:567)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:508)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:123)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1253)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1052)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1103)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1099)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1508)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4268)
	at org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:345)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4160)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4873)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2459)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3655)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
	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:369)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1407)


Reproducible: Always
Comment 1 Florian Lasinger CLA 2011-01-13 11:41:59 EST
Created attachment 186746 [details]
Javascript Testcase - formatting fails
Comment 2 Olivier Thomann CLA 2011-01-13 11:45:07 EST
Moving to jsdt.
Comment 3 Chris Jaun CLA 2011-06-29 09:57:14 EDT
Smaller block of code that produces same error:

function attachConfirmWindow(selector) {
 $element.each(function() {
	$(this).click(function() {
	})
 })
 $('#confirm-button').click(function() {
 this.setAttribute('disabled', 'disabled');
 attachConfirmWindow('#button1');
 });
Comment 4 Chris Jaun CLA 2011-06-29 14:27:06 EDT
Created attachment 198852 [details]
patch
Comment 5 Chris Jaun CLA 2011-06-29 14:28:26 EDT
Just moved the call to get raw source below the check that we have the correct token.

In this case were were at the EOF because of the syntax error in the code.

This should prevent us from trying to read in a token at the EOF.
Comment 6 Nitin Dahyabhai CLA 2011-07-14 02:31:29 EDT
Applied for 3.2.5 and HEAD.  Thank you for the test case, Florian.