Project: JDT
Bug 79318 [ccp] replacing directory with a file of the same name containing this very file will delete file and directory
Reported: 2004-11-23 12:49:48 | Status: resolved fixed

Scenario: There is a directory/folder named "bar" somewhere in the workspace. This directory contains a file also called "bar". The package explorer is used. Problem: When trying to move the file "bar" one level up, Eclipse will show a dialog stating that there already is a file named "bar" in this directory and asking the user if he really wants to overwrite it. (This is correct so far.) If the user clicks "Yes" Eclipse will run into an exception and will show this error dialog: "An exception has been caught while processing the refactoring 'Move'. Reason: Resource /MyProject/bar/bar does not exist." (No entry in .log is created.) There are two buttons: "Undo" and "Abort". No matter what button is clicked, both the directory "bar" and the file "bar" are lost. Presumably Eclipse/JDT deletes/overwrites the directory "bar" before the file "bar" could be read. Possible solutions: * Don't allow the user to move a file that is inside a folder with the same name, so that the file would overwrite the containing directory. * Or: First make a "backup" copy of the file before replacing the directory with this file. (This bug only affects the Package Explorer. The Navigator view does not allow to move files if the containing directory would be replaced.)

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ccp/MoveTest.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/reorg/OverwriteHelper.java