ArrayIndexOutOfBoundsException when using 'Actions on Save' in Eclipse with @Setter annotation #163

Closed
lombokissues opened this Issue Jul 14, 2015 · 20 comments

Projects

None yet

1 participant

@lombokissues
Collaborator

Migrated from Google Code (issue 90)

@lombokissues
Collaborator

๐Ÿ‘ค nzipsi ย  ๐Ÿ•— Dec 19, 2009 at 09:20 UTC

What steps will reproduce the problem?
Take the file below:

import lombok.AccessLevel;
import lombok.Data;
import lombok.Setter;

@ Data
public class TestClass
{

@ Setter(AccessLevel.PRIVATE)
private int doNothing;

}

Put that into Eclipse, and set it up so that will do the following actions
on save (they may not all be needed to reproduce the problem, but they're
what I have):

Format all lines,
Organize Imports,
Remove 'this' qualifier for non-static field access
Remove 'this' qualifier for non-static method access
Change non-static access to static access
Change indirect static access to direct static access
Remove unnecessary blocks.
Convert for loops to enhanced for loops.
Remove unused imports.
Add missing @ Override
Add missing @ Deprecated
Remove unnecessary casts.
Remove trailing whitespace.
Correct indentation.

Make a change to the file and save it. It should generate the following
error:

java.lang.ArrayIndexOutOfBoundsException: 7
at
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.computeMergedMember
Declarations(CodeFormatterVisitor.java:401)
at
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.formatTypeMembers(C
odeFormatterVisitor.java:1992)
at
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatte
rVisitor.java:1190)
at
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatter
Visitor.java:5209)
at
org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclarat
ion.java:1233)
at
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.visit(CodeFormatter
Visitor.java:3076)
at
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(C
ompilationUnitDeclaration.java:647)
at
org.eclipse.jdt.internal.formatter.CodeFormatterVisitor.format(CodeFormatte
rVisitor.java:805)
at
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.formatCompilationUn
it(DefaultCodeFormatter.java:333)
at
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeF
ormatter.java:205)
at
org.eclipse.jdt.internal.formatter.DefaultCodeFormatter.format(DefaultCodeF
ormatter.java:188)
at
org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatt
erUtil.java:288)
at
org.eclipse.jdt.internal.corext.util.CodeFormatterUtil.reformat(CodeFormatt
erUtil.java:351)
at
org.eclipse.jdt.internal.corext.fix.CodeFormatFix.createCleanUp(CodeFormatF
ix.java:69)
at
org.eclipse.jdt.internal.ui.fix.CodeFormatCleanUp.createFix(CodeFormatClean
Up.java:65)
at
org.eclipse.jdt.internal.corext.fix.CleanUpRefactoring.calculateChange(Clea
nUpRefactoring.java:792)
at
org.eclipse.jdt.internal.corext.fix.CleanUpPostSaveListener.saved(CleanUpPo
stSaveListener.java:339)
at
org.codehaus.groovy.eclipse.refactoring.actions.DelegatingCleanUpPostSaveLi
stener.saved(DelegatingCleanUpPostSaveListener.java:129)
at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider$5.ru
n(CompilationUnitDocumentProvider.java:1540)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.noti
fyPostSaveListeners(CompilationUnitDocumentProvider.java:1535)
at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider.comm
itWorkingCopy(CompilationUnitDocumentProvider.java:1332)
at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitDocumentProvider$4.ex
ecute(CompilationUnitDocumentProvider.java:1401)
at
org.eclipse.ui.editors.text.TextFileDocumentProvider$DocumentProviderOperat
ion.run(TextFileDocumentProvider.java:132)
at
org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation.execute(Workspace
ModifyDelegatingOperation.java:69)
at
org.eclipse.ui.actions.WorkspaceModifyOperation$1.run(WorkspaceModifyOperat
ion.java:106)
at
org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1800)
at
org.eclipse.ui.actions.WorkspaceModifyOperation.run(WorkspaceModifyOperatio
n.java:118)
at
org.eclipse.ui.internal.editors.text.WorkspaceOperationRunner.run(Workspace
OperationRunner.java:75)
at
org.eclipse.ui.internal.editors.text.WorkspaceOperationRunner.run(Workspace
OperationRunner.java:65)
at
org.eclipse.ui.editors.text.TextFileDocumentProvider.executeOperation(TextF
ileDocumentProvider.java:456)
at
org.eclipse.ui.editors.text.TextFileDocumentProvider.saveDocument(TextFileD
ocumentProvider.java:772)
at
org.eclipse.ui.texteditor.AbstractTextEditor.performSave(AbstractTextEditor
.java:4945)
at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.performSave(Co
mpilationUnitEditor.java:1230)
at
org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.doSave(Compila
tionUnitEditor.java:1283)
at
org.eclipse.ui.texteditor.AbstractTextEditor$TextEditorSavable.doSave(Abstr
actTextEditor.java:7066)
at org.eclipse.ui.Saveable.doSave(Saveable.java:214)
at
org.eclipse.ui.internal.SaveableHelper.doSaveModel(SaveableHelper.java:346)
at
org.eclipse.ui.internal.SaveableHelper$3.run(SaveableHelper.java:193)
at
org.eclipse.ui.internal.SaveableHelper$5.run(SaveableHelper.java:274)
at
org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.ja
va:464)
at
org.eclipse.jface.operation.ModalContext.run(ModalContext.java:372)
at
org.eclipse.jface.window.ApplicationWindow$1.run(ApplicationWindow.java:759
)
at
org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at
org.eclipse.jface.window.ApplicationWindow.run(ApplicationWindow.java:756)
at
org.eclipse.ui.internal.WorkbenchWindow.run(WorkbenchWindow.java:2578)
at
org.eclipse.ui.internal.SaveableHelper.runProgressMonitorOperation(Saveable
Helper.java:282)
at
org.eclipse.ui.internal.SaveableHelper.runProgressMonitorOperation(Saveable
Helper.java:261)
at
org.eclipse.ui.internal.SaveableHelper.saveModels(SaveableHelper.java:204)
at
org.eclipse.ui.internal.SaveableHelper.savePart(SaveableHelper.java:144)
at
org.eclipse.ui.internal.EditorManager.savePart(EditorManager.java:1357)
at
org.eclipse.ui.internal.WorkbenchPage.savePart(WorkbenchPage.java:3328)
at
org.eclipse.ui.internal.WorkbenchPage.saveEditor(WorkbenchPage.java:3341)
at org.eclipse.ui.internal.SaveAction.run(SaveAction.java:76)
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(LegacyHandler
Wrapper.java:109)
at
org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
at
org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(Parameteri
zedCommand.java:508)
at
org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerServi
ce.java:169)
at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.executeCommand(WorkbenchKeyb
oard.java:470)
at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.press(WorkbenchKeyboard.java
:824)
at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.processKeyEvent(WorkbenchKey
board.java:880)
at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.filterKeySequenceBindings(Wo
rkbenchKeyboard.java:569)
at
org.eclipse.ui.internal.keys.WorkbenchKeyboard.access$3(WorkbenchKeyboard.j
ava:510)
at
org.eclipse.ui.internal.keys.WorkbenchKeyboard$KeyDownFilter.handleEvent(Wo
rkbenchKeyboard.java:125)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.filterEvent(Display.java:1467)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1175)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1200)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1185)
at org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1212)
at
org.eclipse.swt.widgets.Widget.gtk_key_press_event(Widget.java:706)
at
org.eclipse.swt.widgets.Control.gtk_key_press_event(Control.java:2837)
at
org.eclipse.swt.widgets.Composite.gtk_key_press_event(Composite.java:703)
at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1570)
at org.eclipse.swt.widgets.Control.windowProc(Control.java:4586)
at org.eclipse.swt.widgets.Display.windowProc(Display.java:4191)
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:7586)
at org.eclipse.swt.widgets.Display.eventProc(Display.java:1185)
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:1858)
at
org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3110)
at
org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332
)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
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
:194)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication
(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseA
ppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368
)
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:3
9)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
l.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)

Now add in a new method. Can do whatever you want. e.g. private void
doNothing(){}. The error is now gone. What the hell?

Alternatively, remove the @ Setter annotation, or set the AccessLevel to
NONE. Both remove the error. Or add another annotation before @ Setter.

e.g.

@ javax.persistence.Column
@ Setter(AccessLevel.PRIVATE)

If you place another Annotation after @ Setter, the errors continue
popping up.

e.g.

@ Setter(AccessLevel.PRIVATE)
@ javax.persistence.Column

What is the expected output? What do you see instead?

Expected to not see an error.

What version of the product are you using? On what operating system?

Lombok 0.9.2 from the Lombok Maven Repo, Ubuntu 9.04, Sun Java 1.6.0_16,
Eclipse 3.5.

Please provide any additional information below.

Interestingly, the exact place where the AIOOBE occurs changes the more
fields I have in the class. When I first saw it, it was up at 28.

@lombokissues
Collaborator

๐Ÿ‘ค mobile.uwe ย  ๐Ÿ•— Apr 19, 2010 at 07:00 UTC

we face the exact same problem.

@lombokissues
Collaborator

๐Ÿ‘ค marc.schroetel ย  ๐Ÿ•— Apr 25, 2010 at 16:05 UTC

So do I :/

@lombokissues
Collaborator

๐Ÿ‘ค reinierz ย  ๐Ÿ•— Dec 31, 2010 at 21:33 UTC

Issue #243 has been merged into this issue.

@lombokissues
Collaborator

๐Ÿ‘ค reinierz ย  ๐Ÿ•— Dec 31, 2010 at 21:36 UTC

Lombok isn't going to be compatible with save actions for a while, unfortunately. Eclipse fundamentally doesn't grok the notion of AST nodes that are virtual. We'll fix it, eventually, by hiding them for these actions, but that's not an easy task, and some actions actually DO need to see them, such as code analysers, complicating the issue a lot.

@lombokissues
Collaborator

๐Ÿ‘ค grootjans ย  ๐Ÿ•— Jun 20, 2011 at 17:57 UTC

Issue #236 has been merged into this issue.

@lombokissues
Collaborator

๐Ÿ‘ค mart788 ย  ๐Ÿ•— Jul 19, 2011 at 15:33 UTC

It would be good to know what specific formatters are causing this - if there is just one in particular I could turn it off for just that project for example.

@lombokissues
Collaborator

๐Ÿ‘ค BruceMFraser ย  ๐Ÿ•— Jul 26, 2011 at 05:13 UTC

Disabling 'Format source code' under Window > Preferences > Java > Editor > Save Actions and manually formatting with Ctrl+Shift+F works for me.

@lombokissues
Collaborator

๐Ÿ‘ค amanic ย  ๐Ÿ•— Jul 26, 2011 at 06:28 UTC

Sure that is a workaround, but 1) I keep on forgetting to do it and 2) when
it is done automatically you can configure it to only format the lines that
changed.

Comment ๏นŸ7 on issue #163 by BruceMFr...@ gmail.com:
ArrayIndexOutOfBoundsException when using 'Actions on Save' in Eclipse with
@ Setter annotation

issue #163
Disabling 'Format source code' under Window > Preferences > Java > Editor >
Save Actions and manually formatting with Ctrl+Shift+F works for me.

@lombokissues
Collaborator

๐Ÿ‘ค dawid.chodura ย  ๐Ÿ•— Nov 15, 2011 at 09:08 UTC

I have a similar problem. After creating a class and trying to save it, the window "Save Problems" shows up. After clicking "Details..." there is a message:

A save participant caused problems.
The save participant 'Code Clean Up' caused an exception: java.lang.ArrayIndexOutOfBoundsException: 3. See the error log for details.

The only Save Action I have enabled is "Format source code". I do not have enabled "Organize imports" or "Additional actions". If I disable "Format source code" the problem does not occur. If I reenable "Format source code" the problem happens again.

The code of the class:

import lombok.Getter;

public class A {
@ Getter
private int x;
}

I attach the StackTrace from Eclipse Error Log.

Version of lombok: 0.10.1 and 0.10.2, downloaded from http://code.google.com/p/projectlombok/downloads/list
Eclipse version: Helios Service Release 2, Build id: 20110218-0911
Java: 1.6.0_22-b04, Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

@lombokissues
Collaborator

๐Ÿ‘ค dawid.chodura ย  ๐Ÿ•— Nov 15, 2011 at 09:08 UTC

๐Ÿ”— lombok_ArrayIndexOutOfBoundsException_StackTrace.txt View file

@lombokissues
Collaborator

๐Ÿ‘ค reinierz ย  ๐Ÿ•— Nov 15, 2011 at 13:58 UTC

Thanks to another contributor (Jappe van der Hel, he's really been going toe to toe with various eclipse refactor scripts, cleanup actions, etc) I believe this is fixed now. (commit fd736cc and 1950820). Should be out in version after 0.10.2.

Can all people affected by this give the latest edge build a whirl? Please report back here if formatting now works (or doesn't work!) You can find the edge release at:

https://projectlombok.org/download-edge.html

@lombokissues lombokissues added this to the 0.10.3 milestone Jul 14, 2015
@lombokissues
Collaborator

๐Ÿ‘ค reinierz ย  ๐Ÿ•— Nov 15, 2011 at 13:58 UTC

@lombokissues
Collaborator

๐Ÿ‘ค mart788 ย  ๐Ÿ•— Nov 15, 2011 at 15:34 UTC

Since I installed the edge build today, eclipse is hanging when I try to set a breakpoint. I know it doesnt seem related but it was working just fine yesterday before I updated lombok.

@lombokissues
Collaborator

๐Ÿ‘ค dawid.chodura ย  ๐Ÿ•— Nov 15, 2011 at 19:04 UTC

I couldn't find any edge release on the page https://projectlombok.org/download-edge.html

Can you post the direct URL to the edge release jar?

@lombokissues
Collaborator

๐Ÿ‘ค pe.fips ย  ๐Ÿ•— Nov 15, 2011 at 20:26 UTC

0.10.3 is the edge release..
as of 0.10.2 each odd version number marks edge releases

@lombokissues
Collaborator

๐Ÿ‘ค dawid.chodura ย  ๐Ÿ•— Nov 16, 2011 at 07:30 UTC

I tested the "0.10.3 2011-11-15 1356 UTC" edge release. The formatting in Eclipse is working.

I couldn't test it yesterday, because the page https://projectlombok.org/download-edge.html is somehow not accessible from Firefox 8.0 in Windows. It says "No edge build as been released since the last stable release of lombok." That's why I asked for the direct URL for the jar.

I downloaded the page in IE9, Chrome and Firefox in Linux. I also downloaded the page with wget. It works in all the cases but it doesn't work in Firefox 8.0. I don't know why.

@lombokissues
Collaborator

๐Ÿ‘ค reinierz ย  ๐Ÿ•— Nov 21, 2011 at 23:02 UTC

Now in release 0.10.4

@lombokissues lombokissues modified the milestone: 0.10.3, 0.10.4 Jul 14, 2015
@lombokissues
Collaborator

๐Ÿ‘ค twisti4234 ย  ๐Ÿ•— Jan 25, 2012 at 11:27 UTC

Still broken in 10.6 for me

@lombokissues
Collaborator

End of migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment