murat8505 / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 1 forks source link

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

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
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.

Original issue reported on code.google.com by nzipsi@gmail.com on 19 Dec 2009 at 9:20

GoogleCodeExporter commented 9 years ago
we face the exact same problem.

Original comment by mobile....@gmail.com on 19 Apr 2010 at 7:00

GoogleCodeExporter commented 9 years ago
So do I :/

Original comment by marc.sch...@gmail.com on 25 Apr 2010 at 4:05

GoogleCodeExporter commented 9 years ago
Issue 170 has been merged into this issue.

Original comment by reini...@gmail.com on 31 Dec 2010 at 9:33

GoogleCodeExporter commented 9 years ago
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.

Original comment by reini...@gmail.com on 31 Dec 2010 at 9:36

GoogleCodeExporter commented 9 years ago
Issue 163 has been merged into this issue.

Original comment by grootj...@gmail.com on 20 Jun 2011 at 5:57

GoogleCodeExporter commented 9 years ago
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.

Original comment by mart788@gmail.com on 19 Jul 2011 at 3:33

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

Original comment by BruceMFr...@gmail.com on 26 Jul 2011 at 5:13

GoogleCodeExporter commented 9 years ago
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 90 by BruceMFr...@gmail.com:
ArrayIndexOutOfBoundsException when using 'Actions on Save' in Eclipse with
@Setter annotation

http://code.google.com/p/projectlombok/issues/detail?id=90
Disabling 'Format source code' under Window > Preferences > Java > Editor >
Save Actions and manually formatting with Ctrl+Shift+F works for me.

Original comment by ama...@gmail.com on 26 Jul 2011 at 6:28

GoogleCodeExporter commented 9 years ago
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)

Original comment by dawid.ch...@gmail.com on 15 Nov 2011 at 9:08

Attachments:

GoogleCodeExporter commented 9 years ago
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 fd736cc76f6b1b505d73173f270100161988338d and 
1950820d35c1653389a22bddfa3916e125d4bc24). 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:

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

Original comment by reini...@gmail.com on 15 Nov 2011 at 1:58

GoogleCodeExporter commented 9 years ago

Original comment by reini...@gmail.com on 15 Nov 2011 at 1:58

GoogleCodeExporter commented 9 years ago
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.

Original comment by mart788@gmail.com on 15 Nov 2011 at 3:34

GoogleCodeExporter commented 9 years ago
I couldn't find any edge release on the page 
http://projectlombok.org/download-edge.html

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

Original comment by dawid.ch...@gmail.com on 15 Nov 2011 at 7:04

GoogleCodeExporter commented 9 years ago
0.10.3 is the edge release..
as of 0.10.2 each odd version number marks edge releases

Original comment by pe.f...@googlemail.com on 15 Nov 2011 at 8:26

GoogleCodeExporter commented 9 years ago
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 
http://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.

Original comment by dawid.ch...@gmail.com on 16 Nov 2011 at 7:30

GoogleCodeExporter commented 9 years ago
Now in release 0.10.4

Original comment by reini...@gmail.com on 21 Nov 2011 at 11:02

GoogleCodeExporter commented 9 years ago
Still broken in 10.6 for me

Original comment by twisti4...@googlemail.com on 25 Jan 2012 at 11:27