Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 342601 - [rename] Undo of a failed package rename operation doesn't work - Was (JavaModelException during package name refactoring when some files contain errors)
Summary: [rename] Undo of a failed package rename operation doesn't work - Was (JavaMo...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-12 11:56 EDT by Ulli Hafner CLA
Modified: 2018-12-27 14:34 EST (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ulli Hafner CLA 2011-04-12 11:56:45 EDT
Build Identifier: M20110210-1200

When refactoring a package name 'prefix.middle.suffix' to 'prefix.newmiddle.suffix' I always get an exception (the package contains files with java compile errors):

Java Model Exception: Core Exception [code 4] Problems encountered while moving resources.
	at org.eclipse.jdt.internal.core.MultiOperation.processElements(MultiOperation.java:175)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElements(CopyResourceElementsOperation.java:417)
	at org.eclipse.jdt.internal.core.MultiOperation.executeOperation(MultiOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:793)
	at org.eclipse.jdt.internal.core.JavaModel.rename(JavaModel.java:285)
	at org.eclipse.jdt.internal.core.PackageFragment.rename(PackageFragment.java:432)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.renamePackage(RenamePackageChange.java:207)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.doRename(RenamePackageChange.java:136)
	at org.eclipse.jdt.internal.corext.refactoring.AbstractJavaElementRenameChange.perform(AbstractJavaElementRenameChange.java:86)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.access$0(DynamicValidationStateChange.java:1)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange$1.run(DynamicValidationStateChange.java:98)
	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:1975)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4777)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.perform(DynamicValidationStateChange.java:101)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation$1.run(PerformChangeOperation.java:258)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.executeChange(PerformChangeOperation.java:306)
	at org.eclipse.ltk.internal.ui.refactoring.UIPerformChangeOperation.executeChange(UIPerformChangeOperation.java:92)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:218)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.core.internal.resources.ResourceException: Problems encountered while moving resources.
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1609)
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1558)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processPackageFragmentResource(CopyResourceElementsOperation.java:468)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElement(CopyResourceElementsOperation.java:403)
	at org.eclipse.jdt.internal.core.MultiOperation.processElements(MultiOperation.java:163)
	... 27 more
Caused by: org.eclipse.core.internal.resources.ResourceException: Problems encountered while moving resources.
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1609)
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1558)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processPackageFragmentResource(CopyResourceElementsOperation.java:468)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElement(CopyResourceElementsOperation.java:403)
	at org.eclipse.jdt.internal.core.MultiOperation.processElements(MultiOperation.java:163)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElements(CopyResourceElementsOperation.java:417)
	at org.eclipse.jdt.internal.core.MultiOperation.executeOperation(MultiOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:793)
	at org.eclipse.jdt.internal.core.JavaModel.rename(JavaModel.java:285)
	at org.eclipse.jdt.internal.core.PackageFragment.rename(PackageFragment.java:432)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.renamePackage(RenamePackageChange.java:207)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.doRename(RenamePackageChange.java:136)
	at org.eclipse.jdt.internal.corext.refactoring.AbstractJavaElementRenameChange.perform(AbstractJavaElementRenameChange.java:86)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.access$0(DynamicValidationStateChange.java:1)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange$1.run(DynamicValidationStateChange.java:98)
	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:1975)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4777)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.perform(DynamicValidationStateChange.java:101)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation$1.run(PerformChangeOperation.java:258)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.executeChange(PerformChangeOperation.java:306)
	at org.eclipse.ltk.internal.ui.refactoring.UIPerformChangeOperation.executeChange(UIPerformChangeOperation.java:92)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:218)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Contains: Error updating cache during move/delete.
The resource cannot be moved, renamed or deleted due to an internal error.


Reproducible: Always

Steps to Reproduce:
1. Select Package 'hudson.plugins.checkstyle.tokens' in Package explorer. Note that the package contains files with compile errors. 
2. ALT-SHIFT-R
3. Enter new Package name 'hudson.plugins.warnings.tokens' 
4. Select 'update references' and 'rename subpackages'
5. Select 'OK'

Then I get the following exception and the dialog to 'Abort' or 'Undo'. In the package explorer I see that the package 'hudson.plugins.checkstyle.tokens' is empty now (but still is there). The new package is also there with the moved files. 

Pressing 'Abort' does nothing, as well as 'Undo' does not undo. After pressing undo the workspace contains a the new package with the moved classes.The old package is still there (empty). Nothing was undone.
Comment 1 Ayushman Jain CLA 2011-04-13 02:20:24 EDT
Ulli, this may be due to the java files with compilation errors. You can do the refactoring once the errors are resolved and you won't get the exception.

Jay, this seems like the expected behaviour looking at the code. Can you check? Thanks!
Comment 2 Ulli Hafner CLA 2011-04-13 03:46:09 EDT
Seems to be unrelated to the compile errors. After fixing the errors I tried again an got the same exception:

eclipse.buildId=M20110210-1200
java.version=1.6.0_24
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=linux, ARCH=x86, WS=gtk, NL=en_US
Framework arguments:  --launcher.XXMaxPermSize=256m
Command-line arguments:  -os linux -ws gtk -arch x86 -debug /home/hafner/Documents/eclipse.debug -data /home/hafner/Workspaces/Hudson --launcher.XXMaxPermSize=256m


Error
Wed Apr 13 09:44:58 CEST 2011
Internal Error

Java Model Exception: Core Exception [code 4] Problems encountered while moving resources.
	at org.eclipse.jdt.internal.core.MultiOperation.processElements(MultiOperation.java:175)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElements(CopyResourceElementsOperation.java:417)
	at org.eclipse.jdt.internal.core.MultiOperation.executeOperation(MultiOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:793)
	at org.eclipse.jdt.internal.core.JavaModel.rename(JavaModel.java:285)
	at org.eclipse.jdt.internal.core.PackageFragment.rename(PackageFragment.java:432)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.renamePackage(RenamePackageChange.java:207)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.doRename(RenamePackageChange.java:136)
	at org.eclipse.jdt.internal.corext.refactoring.AbstractJavaElementRenameChange.perform(AbstractJavaElementRenameChange.java:86)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.access$0(DynamicValidationStateChange.java:1)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange$1.run(DynamicValidationStateChange.java:98)
	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:1975)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4777)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.perform(DynamicValidationStateChange.java:101)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation$1.run(PerformChangeOperation.java:258)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.executeChange(PerformChangeOperation.java:306)
	at org.eclipse.ltk.internal.ui.refactoring.UIPerformChangeOperation.executeChange(UIPerformChangeOperation.java:92)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:218)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Caused by: org.eclipse.core.internal.resources.ResourceException: Problems encountered while moving resources.
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1609)
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1558)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processPackageFragmentResource(CopyResourceElementsOperation.java:468)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElement(CopyResourceElementsOperation.java:403)
	at org.eclipse.jdt.internal.core.MultiOperation.processElements(MultiOperation.java:163)
	... 27 more
Caused by: org.eclipse.core.internal.resources.ResourceException: Problems encountered while moving resources.
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1609)
	at org.eclipse.core.internal.resources.Resource.move(Resource.java:1558)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processPackageFragmentResource(CopyResourceElementsOperation.java:468)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElement(CopyResourceElementsOperation.java:403)
	at org.eclipse.jdt.internal.core.MultiOperation.processElements(MultiOperation.java:163)
	at org.eclipse.jdt.internal.core.CopyResourceElementsOperation.processElements(CopyResourceElementsOperation.java:417)
	at org.eclipse.jdt.internal.core.MultiOperation.executeOperation(MultiOperation.java:90)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:728)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.jdt.internal.core.JavaModelOperation.runOperation(JavaModelOperation.java:793)
	at org.eclipse.jdt.internal.core.JavaModel.rename(JavaModel.java:285)
	at org.eclipse.jdt.internal.core.PackageFragment.rename(PackageFragment.java:432)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.renamePackage(RenamePackageChange.java:207)
	at org.eclipse.jdt.internal.corext.refactoring.changes.RenamePackageChange.doRename(RenamePackageChange.java:136)
	at org.eclipse.jdt.internal.corext.refactoring.AbstractJavaElementRenameChange.perform(AbstractJavaElementRenameChange.java:86)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.access$0(DynamicValidationStateChange.java:1)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange$1.run(DynamicValidationStateChange.java:98)
	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:1975)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:4777)
	at org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange.perform(DynamicValidationStateChange.java:101)
	at org.eclipse.ltk.core.refactoring.CompositeChange.perform(CompositeChange.java:278)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation$1.run(PerformChangeOperation.java:258)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.executeChange(PerformChangeOperation.java:306)
	at org.eclipse.ltk.internal.ui.refactoring.UIPerformChangeOperation.executeChange(UIPerformChangeOperation.java:92)
	at org.eclipse.ltk.core.refactoring.PerformChangeOperation.run(PerformChangeOperation.java:218)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:1975)
	at org.eclipse.ltk.internal.ui.refactoring.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:87)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Contains: Error updating cache during move/delete.
The resource cannot be moved, renamed or deleted due to an internal error.
Comment 3 Ayushman Jain CLA 2011-04-13 04:18:52 EDT
It'll help if you can attach a reproducible test case or your workspace for us to investigate. Thanks.
Comment 4 Jay Arthanareeswaran CLA 2011-04-13 04:41:49 EDT
I can't reproduce the bug, either. There must be something about the resources in the particular package that are being moved. If you can isolate the problem and share it with us, it would help.
Comment 5 Ulli Hafner CLA 2011-04-13 05:08:40 EDT
I'll try to track down that problem and will attach my workspace.

Anyway, the 'Abort'/'Undo' dialog never worked for me if there was an exception. Can you at least reproduce that problem?
Comment 6 Jay Arthanareeswaran CLA 2011-04-14 04:08:59 EDT
(In reply to comment #5)
> Anyway, the 'Abort'/'Undo' dialog never worked for me if there was an
> exception. Can you at least reproduce that problem?

I have seen it working (though in different scenarios).
Comment 7 Jay Arthanareeswaran CLA 2011-12-22 00:06:06 EST
(In reply to comment #5)
> I'll try to track down that problem and will attach my workspace.

If you are still facing this issue, could you attach your affected workspace. I tried again and can't reproduce the bug. Without being able to reproduce, we can't do much here.
Comment 8 Satyam Kandula CLA 2012-01-23 08:09:24 EST
I am able to reproduce the problem on windows by actually keeping a file in the package opened outside Eclipse. It is natural to expect the move to fail in these conditions. By looking at the call stack, it is move that has failed. However, the user says that all the files are moved but the folder move didn't happen. I cannot speculate the reasons for the failure of the move. One reason I could think of is the underlying SCM is causing the move to fail. Ulli, What SCM are you using? 

With the above steps, I could also reproduce the 'Undo' not working. 
The 'move' problem is probably not something that we need to fix, but I think we should fix the 'Undo' problem. So, I am reopening.
Comment 9 Satyam Kandula CLA 2012-01-23 08:11:23 EST
Changed the summary as per the problem that needs to be fixed. Please Look at comment 8 for more details.
Comment 10 Ulli Hafner CLA 2012-02-21 17:22:55 EST
I'm using git as SCM. I also noticed the undo problem using Windows and subversion plug-in. Very often an exception occurs between an rename package refactoring. Then the undo dialog is presented with both options not working...
Comment 11 Jay Arthanareeswaran CLA 2012-03-05 00:04:17 EST
I managed to reproduce this. But unfortuntely there may not be much we can do here. But whatever the fix is, it has to be done in the JDT/UI. I looked at the code for some time and this is what my investigation shows:

The CompositeChange#handleUndos() looks for the undo change via getUndoUntilException, but it does so only when the change is a CompositeChange. But unfortunately the RenamePackageChange, with which we are dealing here, is not one and no effort is made to undo the changes thus far. 

Now the fix could be as simple as making the RenamePackageChange a CompositeChange, but it is already a ResourceChange. So, either the hierarchy has to be modifies or an alternate fix has to be found out. 

Moving to JDT/UI for further investigation.
Comment 12 Deepak Azad CLA 2012-03-05 00:32:03 EST
(In reply to comment #11)
> I managed to reproduce this. 
Reproduce what?
- What Satyam mentions in comment 8?
- Or the original bug report? 
If it was the second can you please provide the steps to reproduce.
Comment 13 Jay Arthanareeswaran CLA 2012-03-05 23:06:22 EST
(In reply to comment #12)
> Reproduce what?
> - What Satyam mentions in comment 8?
> - Or the original bug report? 
> If it was the second can you please provide the steps to reproduce.

I was particularly talking about the failing 'undo' even though I can reproduce both by just opening the package being renamed in a command prompt - I used a git shell. Of course, we can't do anything about the failing rename action. But we should try and see if the undo can be fixed.
Comment 14 Markus Keller CLA 2012-03-06 08:17:40 EST
The only way we could fix this is by implementing RenamePackageChange manually without using IPackageFragment#rename(..).
Comment 15 Markus Keller CLA 2012-03-06 08:30:15 EST
I can reproduce similar errors by keeping a *.txt file open in Lotus Symphony or by having a cmd.exe prompt with the package's folder as current directory.

Ulli: Your stacktraces contain "Contains: Error updating cache during move/delete.". I didn't find this message in the Eclipse SDK, but it looks like it's coming from org.eclipse.egit.core.GitMoveDeleteHook.
Please file a new bug for EGit/Core if you have more information about when this happens.
Comment 16 Eclipse Genie CLA 2018-12-27 14:34:12 EST
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.

If you have further information on the current state of the bug, please add it. 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.