Bug 63181 - Protected field access forbidden outside package
Summary: Protected field access forbidden outside package
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 blocker (vote)
Target Milestone: 3.0 M9   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-20 07:08 EDT by Andrew Larder CLA
Modified: 2004-05-20 07:42 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Larder CLA 2004-05-20 07:08:00 EDT
Accessing a protected field in a super-class from outide of the package the 
super-class was defined in, results in Eclipse claiming that 'the field <...> 
is not visible'.

Tried it on 3.0M8 and it doesn't work, but everythings ok on the 2.1.2 build:

Example of problem:

package packageA;
public abstract class BaseClass {
  protected BaseClass parent;
  protected int myField;
  protected abstract myMethod();
}

package packageA.subpackage;
public class DerivedClass {
  protected myMethod() {
    int a = parent.myField;
  }
}

Here Eclipse claims that myField is not visible. Is this correct behaviour?
Comment 1 Philipe Mulet CLA 2004-05-20 07:40:26 EDT
Your test case was incomplete. The following one does issue a compile error 
which is indeed expected.

package packageA;
public abstract class BaseClass {
  protected BaseClass parent;
  protected int myField;
  protected abstract void myMethod();
}

package packageA.subpackage;
import packageA.BaseClass;
public class DerivedClass extends BaseClass {
  protected void myMethod() {
    int a = parent.myField;
  }
}


myField is a protected field, and thus can only be used from within same 
package or type hierarchy as long as it is applied to itself or a subclass
(jls 6.6.2.1).


Comment 2 Philipe Mulet CLA 2004-05-20 07:42:39 EDT
Eclipse 2.1.3 did also correctly report this problem either.