Bug 233413 - [move type] move type creates invalid import to default package
Summary: [move type] move type creates invalid import to default package
Status: ASSIGNED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P4 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-22 05:28 EDT by Andreas Goetz CLA
Modified: 2021-07-19 08:56 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Goetz CLA 2008-05-22 05:28:16 EDT
I have my code setup in the default package:

class A implements B;
class C;
interface B {
	method m{C c};
}

moving the interface B to a new interfaces package creates interfaces\interface B which imports C which isn't available and results is a compiler error;

I believe it would be beneficial if imports from default package would be marked as warnings when refactoring to different pacakges.
Comment 1 Jerome Lanneluc CLA 2008-05-22 08:46:45 EDT
Moving to JDT/UI
Comment 2 Felix Pahl CLA 2021-07-19 08:56:43 EDT
This is still relevant in 4.19 (Version: 2021-03 (4.19.0), Build id: 20210312-0638).

As the original example is incomplete and unnecessarily complicated, here's a restatement of the problem:

If a type is moved to a different package (by dragging it there in the Package Explorer or using the "Move" refactoring), type references across packages (in both directions) cause errors if the types referred to are not public. For instance, in the following code:

// A.java
package original;
class A extends B {};

// B.java
package original;
class B { C c; }

// C.java
package original;
class C {}

moving B to package "interfaces" generates the line

import interfaces.B;

in A.java, which doesn't compile since B isn't public, and the line

import original.C;

in B.java, which doesn't compile since C isn't public.

The solution would be to make the classes that are being referred to across packages public (or to provide an option to do so).