Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 408247

Summary: [dnd] Dropping method inside an enum causes exceptions
Product: [Eclipse Project] JDT Reporter: Jörg Thönnes <jtk499>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert
Version: 3.2Keywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug
Attachments:
Description Flags
Stripped down example code
none
Screen shot of insertion point. none

Description Jörg Thönnes CLA 2013-05-16 10:23:48 EDT
I usually move methods using the Outline view. Now moving resulted in an internal error (java.lang.ArrayIndexOutOfBoundsException: -1)

What steps will reproduce the problem?
1. Create Java enum
1.1 implementing an interface with at least 2 methods,
1.2 with several enums at the beginning,
1.3 having one string argument in the enum constructor,
1.4 implementing the interface methods per enum constant (like anonymous subclasses)
2. Add 2 top-level interfce methods to the end
3. Select these new methods in Outline view
4. Drop these methods at the beginning of the enum (before enum constant definitions).

Result: Popup with internal error, error log entry see below.

-- Error Details --
Date: Thu May 16 16:16:40 CEST 2013
Message: Internal Error
Severity: Error
Product: Eclipse SDK 3.8.2.v201301310800 (org.eclipse.sdk.ide)
Plugin: org.eclipse.jdt.ui
Session Data:
eclipse.buildId=M20130131-0800
java.version=1.6.0_43
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US
Framework arguments:  -eclipse.password /home/jt/.eclipse/Eclipse.password
Command-line arguments:  -os linux -ws gtk -arch x86_64 -eclipse.password /home/jt/.eclipse/Eclipse.password

Exception Stack Trace:
java.lang.reflect.InvocationTargetException
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:477)
	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:2649)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:191)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:151)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgMoveStarter.run(ReorgMoveStarter.java:70)
	at org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter.handleDropMove(SelectionTransferDropAdapter.java:283)
	at org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter.performDrop(SelectionTransferDropAdapter.java:220)
	at org.eclipse.jdt.internal.ui.dnd.JdtViewerDropAdapter.drop(JdtViewerDropAdapter.java:246)
	at org.eclipse.jface.util.DelegatingDropAdapter$3.run(DelegatingDropAdapter.java:211)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
	at org.eclipse.jface.util.DelegatingDropAdapter.drop(DelegatingDropAdapter.java:209)
	at org.eclipse.swt.dnd.DNDListener.handleEvent(DNDListener.java:90)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1300)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1285)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1079)
	at org.eclipse.swt.dnd.DropTarget.drag_data_received(DropTarget.java:371)
	at org.eclipse.swt.dnd.DropTarget.Drag_Data_Received(DropTarget.java:251)
	at org.eclipse.swt.internal.gtk.OS._gtk_drag_get_data(Native Method)
	at org.eclipse.swt.internal.gtk.OS.gtk_drag_get_data(OS.java:6743)
	at org.eclipse.swt.dnd.DropTarget.drag_drop(DropTarget.java:416)
	at org.eclipse.swt.dnd.DropTarget.Drag_Drop(DropTarget.java:258)
	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:8317)
	at org.eclipse.swt.widgets.Display.eventProc(Display.java:1193)
	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:2342)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3184)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	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:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	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:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.get(ArrayList.java:324)
	at java.util.Collections$UnmodifiableList.get(Collections.java:1152)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.insertRelative(ReorgPolicyFactory.java:3804)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.copyMemberToDestination(ReorgPolicyFactory.java:3758)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.copyMethodToDestination(ReorgPolicyFactory.java:3815)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.copyToDestination(ReorgPolicyFactory.java:3842)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$MoveSubCuElementsPolicy.createChange(ReorgPolicyFactory.java:2227)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor.createChange(JavaMoveProcessor.java:169)
	at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.createChange(ProcessorBasedRefactoring.java:292)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run(RefactoringExecutionHelper.java:97)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5204)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:106)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:464)
	... 55 more
Root exception:
java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.ArrayList.get(ArrayList.java:324)
	at java.util.Collections$UnmodifiableList.get(Collections.java:1152)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.insertRelative(ReorgPolicyFactory.java:3804)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.copyMemberToDestination(ReorgPolicyFactory.java:3758)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.copyMethodToDestination(ReorgPolicyFactory.java:3815)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$SubCuElementReorgPolicy.copyToDestination(ReorgPolicyFactory.java:3842)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.ReorgPolicyFactory$MoveSubCuElementsPolicy.createChange(ReorgPolicyFactory.java:2227)
	at org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor.createChange(JavaMoveProcessor.java:169)
	at org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.createChange(ProcessorBasedRefactoring.java:292)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.run(RefactoringExecutionHelper.java:97)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5204)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:106)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java: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:2649)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:191)
	at org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform(RefactoringExecutionHelper.java:151)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgMoveStarter.run(ReorgMoveStarter.java:70)
	at org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter.handleDropMove(SelectionTransferDropAdapter.java:283)
	at org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter.performDrop(SelectionTransferDropAdapter.java:220)
	at org.eclipse.jdt.internal.ui.dnd.JdtViewerDropAdapter.drop(JdtViewerDropAdapter.java:246)
	at org.eclipse.jface.util.DelegatingDropAdapter$3.run(DelegatingDropAdapter.java:211)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
	at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
	at org.eclipse.jface.util.DelegatingDropAdapter.drop(DelegatingDropAdapter.java:209)
	at org.eclipse.swt.dnd.DNDListener.handleEvent(DNDListener.java:90)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1276)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1300)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1285)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1079)
	at org.eclipse.swt.dnd.DropTarget.drag_data_received(DropTarget.java:371)
	at org.eclipse.swt.dnd.DropTarget.Drag_Data_Received(DropTarget.java:251)
	at org.eclipse.swt.internal.gtk.OS._gtk_drag_get_data(Native Method)
	at org.eclipse.swt.internal.gtk.OS.gtk_drag_get_data(OS.java:6743)
	at org.eclipse.swt.dnd.DropTarget.drag_drop(DropTarget.java:416)
	at org.eclipse.swt.dnd.DropTarget.Drag_Drop(DropTarget.java:258)
	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:8317)
	at org.eclipse.swt.widgets.Display.eventProc(Display.java:1193)
	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:2342)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3184)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
	at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
	at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)
	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:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	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:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)
Comment 1 Jörg Thönnes CLA 2013-05-16 10:28:55 EDT
Created attachment 231089 [details]
Stripped down example code

Attached my code (removed package, comments and renamed some item).
Comment 2 Jörg Thönnes CLA 2013-05-16 10:34:53 EDT
Created attachment 231090 [details]
Screen shot of insertion point.

The same also happens if moving one method exactly between enum name and first enum definition.
Comment 3 Jörg Thönnes CLA 2013-05-16 10:35:40 EDT
Sorry, screen is broken, but maybe you get the point...
Comment 4 Jörg Thönnes CLA 2013-05-17 03:12:30 EDT
Now as I moved the method by hand I noted that the place at the beginning is syntactically incorrect :-)

But normally Eclipse would allow this move and just decorate the moved lines with error indicators.
So I continue to see this as a bug.
Comment 5 Dani Megert CLA 2013-05-17 05:00:36 EDT
Dropping almost anywhere causes an issue:

Simpler test case:

public enum Bug {
	TEST() {
	};
	public void dndMeAboveTEST() {
	}
}

Dropping above TEST, causes the AIOOBE, dropping below TEST copies the method and dropping into TEST causes an NPE.
Comment 6 Jörg Thönnes CLA 2013-05-23 07:10:38 EDT
Will this issue be corrected?
Comment 7 Dani Megert CLA 2013-05-23 07:23:08 EDT
(In reply to comment #6)
> Will this issue be corrected?

Definitely not for Kepler and it's not high on our list. A patch is welcome.
Comment 8 Jörg Thönnes CLA 2013-05-28 02:58:30 EDT
Dani, I am sorry, but I am no GUI developer at all, JEE is my main focus.

Therefore, I cannot supply any patches. Actually, I wonder whether this bug is so complicated that it will not be corrected for the next major release. I would expect that corrections always supersede new features.

Thanks, Jörg
Comment 9 Dani Megert CLA 2013-05-28 03:20:02 EDT
(In reply to comment #8)
> I would expect that corrections always supersede new features.

That's the wrong expectation then. Of course critical bugs will be addressed before new features. But I'll invest the resources rather into a new feature than working on a DnD bug, which no one reported for the past 7 years. Plus, since it is open source, anyone who finds the bug important enough, can invest his own time to address the problem.
Comment 10 Jörg Thönnes CLA 2013-05-28 03:32:18 EDT
OK, understood that you have different priorities and cannot fulfill my expectations. But it could as well be a regression introduced by recent changes.
This could also explain no reports for 7 years.

Thanks, Jörg
Comment 11 Dani Megert CLA 2013-05-28 04:00:48 EDT
(In reply to comment #10)
> OK, understood that you have different priorities and cannot fulfill my
> expectations. But it could as well be a regression introduced by recent
> changes.

If I set the version to '3.2' it really means that the bug is in there since 3.2 ;-).
Comment 12 Jörg Thönnes CLA 2013-05-28 04:34:59 EDT
:-) not intended to argue too much...

Do you have some pointers where to start looking for this issue?

From the stack trace I would conclude the package
"org.eclipse.jdt.internal.corext.refactoring.reorg"
which sounds more like the JDT refactoring than UI.
Comment 13 Dani Megert CLA 2013-05-28 04:41:48 EDT
(In reply to comment #12)
> :-) not intended to argue too much...
> 
> Do you have some pointers where to start looking for this issue?
> 
> From the stack trace I would conclude the package
> "org.eclipse.jdt.internal.corext.refactoring.reorg"
> which sounds more like the JDT refactoring than UI.

The corext packages contain extensions to JDT Core, which live in JDT UI.
http://git.eclipse.org/c/jdt/eclipse.jdt.ui.git/

http://wiki.eclipse.org/JDT_UI/How_to_Contribute#Contributing_Code gives an entry point on how to contribute code.
Comment 14 Jörg Thönnes CLA 2013-05-28 05:01:40 EDT
Thanks, Jörg.
Comment 15 Eclipse Genie CLA 2020-05-01 04:35:44 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.