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

Bug 67046

Summary: Exception when dragging a method to another class using the package explorer
Product: [Eclipse Project] JDT Reporter: Hanna Farah <farahtech2002>
Component: TextAssignee: Christof Marti <christof_marti>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P2 CC: dirk_baeumer, eclipse, kai-uwe_maetzel, markus.kell.r
Version: 3.0   
Target Milestone: 3.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 62862    
Attachments:
Description Flags
Minimal patch that moves the call to super() between un-/configure()
none
The PresentationReconciler should take up an initial document
none
AbstractReconciler should take up an initial document too
none
Patch to be applied to AbstractReconciler.java none

Description Hanna Farah CLA 2004-06-14 13:36:29 EDT
a.	Create a new Java project
b.	Create 3 new packages
c.	Create a new class in each of the first 2 packages
d.	Add 2 methods to the class in the second package and save it
e.	Move the previous class with the 2 methods to the third package
f.	Try to drag and drop a method from the previous class in the package 
explorer to the first class (in order to move this method to the first class)
g.	Notice that the method is still visible in both classes
h.	Try to drag it again from the second class to the first one
i.	An exception occurs since the second class no longer contained that 
method

Here is the session data:
eclipse.buildId=I200406111814
java.version=1.4.2_03
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US

Here is the stack trace:

Java Model Exception: Java Model Status [c() [in a2 [in [Working copy] a2.java 
[in p3 [in <project root> [in SWTTest]]]]] does not exist]
	at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException
(JavaElement.java:561)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed
(JavaElement.java:583)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo
(JavaElement.java:309)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo
(JavaElement.java:295)
	at org.eclipse.jdt.internal.core.Member.getFlags(Member.java:154)
	at org.eclipse.jdt.internal.corext.util.JdtFlags.isPrivate
(JdtFlags.java:82)
	at 
org.eclipse.jdt.internal.corext.refactoring.participants.JavaProcessors.compute
AffectedNatures(JavaProcessors.java:32)
	at 
org.eclipse.jdt.internal.corext.refactoring.participants.JavaProcessors.compute
AffectedNaturs(JavaProcessors.java:43)
	at 
org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor.getAffected
ProjectNatures(JavaMoveProcessor.java:115)
	at 
org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor.loadPartici
pants(JavaMoveProcessor.java:111)
	at 
org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring.checkFi
nalConditions(ProcessorBasedRefactoring.java:142)
	at org.eclipse.ltk.core.refactoring.Refactoring.checkAllConditions
(Refactoring.java:126)
	at 
org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper$Operation.ru
n(RefactoringExecutionHelper.java:65)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation
(BatchOperation.java:34)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run
(JavaModelOperation.java:700)
	at org.eclipse.core.internal.resources.Workspace.run
(Workspace.java:1673)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:3246)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run
(WorkbenchRunnableAdapter.java:65)
	at org.eclipse.jface.operation.ModalContext.runInCurrentThread
(ModalContext.java:303)
	at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:253)
	at org.eclipse.jface.dialogs.ProgressMonitorDialog.run
(ProgressMonitorDialog.java:397)
	at 
org.eclipse.jdt.internal.ui.refactoring.RefactoringExecutionHelper.perform
(RefactoringExecutionHelper.java:116)
	at org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgMoveStarter.run
(ReorgMoveStarter.java:78)
	at 
org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter.handleDrop
Move(SelectionTransferDropAdapter.java:208)
	at 
org.eclipse.jdt.internal.ui.packageview.SelectionTransferDropAdapter.drop
(SelectionTransferDropAdapter.java:132)
	at org.eclipse.jdt.internal.ui.dnd.JdtViewerDropAdapter.drop
(JdtViewerDropAdapter.java:112)
	at org.eclipse.jdt.internal.ui.dnd.DelegatingDropAdapter.drop
(DelegatingDropAdapter.java:79)
	at org.eclipse.swt.dnd.DNDListener.handleEvent(DNDListener.java:65)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:820)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:805)
	at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:613)
	at org.eclipse.swt.dnd.DropTarget.notifyListeners(DropTarget.java:507)
	at org.eclipse.swt.dnd.DropTarget.Drop(DropTarget.java:428)
	at org.eclipse.swt.dnd.DropTarget.access$7(DropTarget.java:363)
	at org.eclipse.swt.dnd.DropTarget$3.method6(DropTarget.java:232)
	at org.eclipse.swt.internal.ole.win32.COMObject.callback6
(COMObject.java:115)
	at org.eclipse.swt.internal.ole.win32.COM.DoDragDrop(Native Method)
	at org.eclipse.swt.dnd.DragSource.drag(DragSource.java:277)
	at org.eclipse.swt.dnd.DragSource.access$0(DragSource.java:263)
	at org.eclipse.swt.dnd.DragSource$1.handleEvent(DragSource.java:157)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:82)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:796)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:2732)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2398)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1362)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1333)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench
(Workbench.java:252)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:141)
	at org.eclipse.ui.internal.ide.IDEApplication.run
(IDEApplication.java:96)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run
(PlatformActivator.java:334)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:272)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run
(EclipseStarter.java:128)
	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:324)
	at org.eclipse.core.launcher.Main.basicRun(Main.java:185)
	at org.eclipse.core.launcher.Main.run(Main.java:638)
	at org.eclipse.core.launcher.Main.main(Main.java:622)
Comment 1 Dirk Baeumer CLA 2004-06-14 18:10:23 EDT
Markus, can you please investigate and asses how important this is for 3.0.
Comment 2 Markus Keller CLA 2004-06-16 09:41:08 EDT
Can reproduce: 
- create packages p1, p2, and p3.
- create class p1.C1 with wizard; close editor.
- create class p2.C2 with wizard
- add empty methods one() and two() to C2
- save the editor but do *not* close it
- move p2/C2.java to p3
- drill down to p3/C2.java/C2 and drag one() to C1.java/C1

We don't get a REMOVED IJavaElementDelta for one(). This is why p3.C2#one()
stays in the PackageExplorer. The problem is that the reconciler seems to be
completely quiet after CU has been moved.

The exception is only a consequence of touching the (outdated) java element of
the moved method.
Comment 3 Markus Keller CLA 2004-06-16 11:24:04 EDT
Tom, could you please have a look at what the reconciler does?
Comment 4 Tom Hofmann CLA 2004-06-16 12:02:41 EDT
It looks like we are uninstalling the reconciler but not re-install it again.
Comment 5 Tom Hofmann CLA 2004-06-16 12:19:07 EDT
- JavaSourceViewerConfiguration.getReconciler(ISourceViewer) line: 413 returns
null because it thinks the editor is read-only.
- the editor thinks it is read-only because it still refers to the old
(p2/C2.java) file, which does not exist.
Comment 6 Kai-Uwe Maetzel CLA 2004-06-16 12:57:41 EDT
Second RC3 vote required.
Comment 7 Kai-Uwe Maetzel CLA 2004-06-16 13:58:05 EDT
Approved by Dirk & Kai.
Comment 8 Christof Marti CLA 2004-06-17 09:33:54 EDT
The problem is in JavaEditor#doSetInput(): The source viewer is configured
before the new input has been set. During configuration the source viewer
requests a reconciler which is 'null' because the old input is still connected
to the document provider. The new input gets set and connected too late.
Comment 9 Christof Marti CLA 2004-06-17 09:39:40 EDT
Created attachment 12383 [details]
Minimal patch that moves the call to super() between un-/configure()
Comment 10 Christof Marti CLA 2004-06-17 09:46:02 EDT
Created attachment 12385 [details]
The PresentationReconciler should take up an initial document

The previous patch triggers another problem: PresentationReconciler#install()
does not check whether the document has already been set on the viewer and in
this case never registers its internal listener on the document and the widget.


Previous to the support of project settings the PresentationReconciler was
reused on doSetInput() - now a new PresentationReconciler is instantiated when
configuring the source viewer on doSetInput().
Comment 11 Christof Marti CLA 2004-06-17 10:27:16 EDT
Created attachment 12386 [details]
AbstractReconciler should take up an initial document too

Additional ripple of the inital patch.
Comment 12 Christof Marti CLA 2004-06-17 10:48:47 EDT
When opening an editor we call in that order:
- IDocumentProvider#connect(..)
- ISourceViewer#configure(..)
- ITextViewer#setDocument(..)

Each call depends on the previous.

When reusing an editor: RC2 calls configure(), connect(), setDocument(). The
patch moves configure() to the end. connect() and setDocument() are called as
part of AbstractTextEditor#doSetInput().
Comment 13 Christof Marti CLA 2004-06-18 11:50:12 EDT
Reviewed by DM. Fixed in HEAD. Will be released into I200406181600.
Comment 14 Thomas M??der CLA 2004-06-21 04:25:35 EDT
starting to verify.
Comment 15 Thomas M??der CLA 2004-06-21 04:31:36 EDT
Not fixed. I get the same behaviour as initially reported on RC 3.
Comment 16 Dani Megert CLA 2004-06-23 14:25:59 EDT
We detected one part of the problem and fixed it. Then, while testing it we
missed the important part of the test scenario: we reused the project setup
described in comment 0 a. to d. opened the files and then continued. As it turns
out, the really important part is "save it" in step d.

In our fix we re-install the reconciler using IReconciler.install(ITextViewer)
and here's the second not-fixed part of the problem:
AbstractReconciler.install(ITextViewer) makes the non-speced assumption that the
viewer hasn't a document yet and that the reconciler will be triggered via
ITextInputListener. This is not true in our case: the viewer has its document
already set.

I've attached a patch to AbstractReconciler which removes the assumptions from
AbstractReconciler.install(ITextViewer) and AbstractReconciler.unstall(ITextViewer).

Open issue: investigate why the save triggers the bug.

Comment 17 Dani Megert CLA 2004-06-23 14:27:03 EDT
Created attachment 12740 [details]
Patch to be applied to AbstractReconciler.java
Comment 18 Kai-Uwe Maetzel CLA 2004-06-25 11:05:24 EDT
Will be fixed post 3.0. Changing target milestone.
Comment 19 Dani Megert CLA 2004-07-29 09:58:10 EDT
This fix had to be put into 3.0.1 in order to fix bug 62862.
Comment 20 Andre Weinand CLA 2004-08-11 10:09:29 EDT
started verifying...
Comment 21 Andre Weinand CLA 2004-08-11 10:25:22 EDT
verified for 3.1 M1
Comment 22 Dani Megert CLA 2004-09-02 04:11:18 EDT
Verified in M200409010800.