Details
-
Type:
Bug
-
Status: Closed
-
Priority:
P4
-
Resolution: Won't Fix
-
Affects Version/s: 1.2.2
-
Fix Version/s: None
-
Component/s: tools
-
Labels:
-
Subcomponent:
-
CPU:generic
-
OS:solaris_8
Description
The javac compiler incorrectly disallows access to members of protected
inner classes from classes belonging to a different package.
Consider the following two source files:
----------------
package a;
public class A {
protected class In {
public void method() {
System.out.println("A.In.method called");
}
}
}
----------------
import a.*;
public class B extends A {
private class B_In extends A.In {
public void method() {
System.out.println("about to call super.method");
super.method();
}
}
public void callMethod() {
B_In bin = new B_In();
bin.method();
}
public static void main(String[] args) {
B b = new B();
b.callMethod();
}
}
----------------
Compiling these two files induces the following error message:
. javac a/A.java B.java
B.java:7: The type a.A.In to which the member method belongs is not
accessible from inner class B. B_In.
super.method();
^
1 error
.
Putting both files into the same package eliminates the problem.
I discovered this problem by trying to subclass
javax.swing.JTabbedPane.ModelListener as discussed in the comment preceding its
definition:
/**
* Subclasses that want to handle ChangeEvents differently
* can override this to return a subclass of ModelListener or
* another ChangeListener implementation.
*/
So the problem has practical impact.
inner classes from classes belonging to a different package.
Consider the following two source files:
----------------
package a;
public class A {
protected class In {
public void method() {
System.out.println("A.In.method called");
}
}
}
----------------
import a.*;
public class B extends A {
private class B_In extends A.In {
public void method() {
System.out.println("about to call super.method");
super.method();
}
}
public void callMethod() {
B_In bin = new B_In();
bin.method();
}
public static void main(String[] args) {
B b = new B();
b.callMethod();
}
}
----------------
Compiling these two files induces the following error message:
. javac a/A.java B.java
B.java:7: The type a.A.In to which the member method belongs is not
accessible from inner class B. B_In.
super.method();
^
1 error
.
Putting both files into the same package eliminates the problem.
I discovered this problem by trying to subclass
javax.swing.JTabbedPane.ModelListener as discussed in the comment preceding its
definition:
/**
* Subclasses that want to handle ChangeEvents differently
* can override this to return a subclass of ModelListener or
* another ChangeListener implementation.
*/
So the problem has practical impact.