Bug 213283 - [formatter] AIOOBE when formatting region
Summary: [formatter] AIOOBE when formatting region
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.4 M5   Edit
Assignee: Eric Jodet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-18 04:17 EST by Benno Baumgartner CLA
Modified: 2008-02-05 07:03 EST (History)
3 users (show)

See Also:


Attachments
[proposed patch + test cases] on top v830 - all jdt.core tests OK (16.21 KB, patch)
2007-12-20 06:55 EST, Eric Jodet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Benno Baumgartner CLA 2007-12-18 04:17:05 EST
I20071213-1700

Given:
package test1;
public class E1 {

	public int        field;
}

1. Select complete line with field decl
2. Format
Is:
java.lang.ArrayIndexOutOfBoundsException: 4
	at org.eclipse.jdt.internal.compiler.util.Util.getLineNumber(Util.java:289)
	at org.eclipse.jdt.internal.formatter.Scribe.isAdaptableRegion(Scribe.java:747)
	at org.eclipse.jdt.internal.formatter.Scribe.adaptRegions(Scribe.java:127)
	at org.eclipse.jdt.internal.formatter.Scribe.getRootEdit(Scribe.java:623)
	at org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatterVisitor.java:806)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.formatCompilationUnit(DefaultCodeFormatter.java:297)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:176)
	at org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeFormatter.java:160)
	at org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatterUtil.java:288)
	at org.eclipse.jdt.internal.ui.text.java.JavaFormattingStrategy.format(JavaFormattingStrategy.java:64)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.formatMaster(MultiPassContentFormatter.java:193)
	at org.eclipse.jface.text.formatter.MultiPassContentFormatter.format(MultiPassContentFormatter.java:135)
	at org.eclipse.jface.text.source.SourceViewer.doOperation(SourceViewer.java:836)
	at org.eclipse.jface.text.source.projection.ProjectionViewer.doOperation(ProjectionViewer.java:1511)
	at org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.doOperation(JavaSourceViewer.java:178)
	at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor$AdaptedSourceViewer.doOperation(CompilationUnitEditor.java:195)
	at org.eclipse.ui.texteditor.TextOperationAction$1.run(TextOperationAction.java:131)
	at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
	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:475)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:470)
	at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:165)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyboard.java:470)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java:821)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKeyboard.java:879)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(WorkbenchKeyboard.java:568)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.java:510)
	at org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(WorkbenchKeyboard.java:126)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1160)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:951)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:976)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:961)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:989)
	at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:985)
	at org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1301)
	at org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:3883)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:3776)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:334)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4450)
	at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
	at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2329)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3359)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2381)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2345)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2211)
	at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:473)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:288)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:468)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:193)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:362)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:175)
	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:585)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:561)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:501)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1239)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1215)

Major or critical: This also happens on save if format edited lines is enabled.
Comment 1 Eric Jodet CLA 2007-12-18 04:20:39 EST
investigating
Comment 2 Eric Jodet CLA 2007-12-20 06:55:39 EST
Created attachment 85645 [details]
[proposed patch + test cases] on top v830 - all jdt.core tests OK

Proposed patch also fixes bug 213284, though not a dup of this one.
Added several test cases that are variation of bug 208541, bug 213283 and bug 213284.

All jdt.core, jdt.ui and jdt.text tests passed OK.
Comment 3 Eric Jodet CLA 2007-12-20 06:56:55 EST
(In reply to comment #1)
> investigating

Side effect of bug 208541 correction.

Comment 4 Benno Baumgartner CLA 2007-12-20 08:28:27 EST
Uff, this is quite complex, hard to tell. I have reviewed the patch and it
looks ok, I've also formatted thousands of random regions in jdt/ui and
jdt/core without a failure.
Comment 5 Eric Jodet CLA 2007-12-20 08:58:35 EST
(In reply to comment #4)
thanks for the additional tests, Benno.
Comment 6 Eric Jodet CLA 2007-12-21 00:41:55 EST
Patch released for 3.4M5 in HEAD.
Comment 7 Jerome Lanneluc CLA 2008-02-05 06:29:46 EST
Exact steps to reproduce are:
1. Create a cu with the following content:
------------------------------------------
package test1;
public class E1 {

        public int        field;
}
------------------------------------------
2. Put text cursor on line 4 column 1
3. Shift+End
4. Ctrl+Shift+F
Observe: You get an error dialog. The ArrayIndexOutOfBoundsException is in the .log file

This error doesn't occur with 3.4M5.

Verified for 3.4M5 using I20080204-0010
Comment 8 Jerome Lanneluc CLA 2008-02-05 07:03:45 EST
(In reply to comment #7)
> Exact steps to reproduce are:
> 1. Create a cu with the following content:
> ------------------------------------------
> package test1;
> public class E1 {
> 
>         public int        field;
> }
> ------------------------------------------
Note the last character of the file must be the closing brace. If a new line is inserted after the last closing brace, the bug doesn't occur.