Bug 117282

Summary: Package declaration inserted on wrong CU while copying class if names collide and editor opened
Product: [Eclipse Project] JDT Reporter: Frederic Fusier <frederic_fusier>
Component: CoreAssignee: Jerome Lanneluc <jerome_lanneluc>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: markus.kell.r
Version: 3.2   
Target Milestone: 3.2 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed patch and regression test none

Description Frederic Fusier CLA 2005-11-21 04:05:57 EST
Using build I20051116-1332.

Here's my projects setup:
Project 'P'
  <default package>
    Test.java
      public class Test {
        <TP extends Test> void m(Test methodParam) {
          Test localVar;
          for (java.util.List<Test> localVar2;;) {
          }
        }
      }

Project 'Test'
  b110336
    Test.java
      package b110336;
      public class Test {
        // This class is empty (created using wizard...)
      }

Now here's the story...

I had a class Test in default package in a project 'P'. I created a new class 'Test' in package b110336 in another project 'Test'. As I used the wizard to create this class, I had an editor opened on this new empty class.

Then, I wanted to copy my test class Test.java of project 'P' in package b110336 of project 'Test'. So I used 'Copy' menu item on project 'P' Test.java class, selected package b110336 of project 'Test' and clicked on 'Paste' menu item...
I was asked if I wanted to overwrite the exisiting destination and I answered yes.

But result was really strange as I saw in the opened editor a duplicate line:
      package b110336;
of course flagged as error...
I wanted to cancel this change and closed the opened editor, then I got a message saying that file has been changed on file system. I loaded changes and then got the content of project 'P' class Test without the package declaration. Of course all class contents was flagged as error due to the fact that the declared package does not match the expected one...

It seems that package declaration insertion was done on working copy of opened editor instead of contents pasted from copied CU...
Comment 1 Martin Aeschlimann CLA 2005-11-22 11:58:22 EST
Markus, can you have a look?
Comment 2 Markus Keller CLA 2005-11-23 09:13:41 EST
Looks like a problem in ICompilationUnit#copy(..). Moving to JDT/Core.

We call that method on P/Test.java and copy it to the package b110336 with force==true. Right when that call comes back, the buffer of the ICompilationUnit Test/b110336/Test.java contains the two package declarations. The copy operation should only change the contents of the working copy and not touch the file system.
Comment 3 Jerome Lanneluc CLA 2005-12-14 13:19:46 EST
Created attachment 31769 [details]
Proposed patch and regression test
Comment 4 Jerome Lanneluc CLA 2006-01-06 07:23:02 EST
Released fix and regression test to HEAD
Comment 5 Frederic Fusier CLA 2006-02-14 05:51:52 EST
Verified for 3.2 M5 using build I20060214-0010.