-
Bug
-
Resolution: Duplicate
-
P3
-
None
-
1.0.2
-
sparc
-
solaris_2.4
Name: vsC45997 Date: 10/15/96
The section "6.6.1 Determining Accessibility" of The Java Language
Specification contains the following:
"If a class or interface type is declared public, then it may be accessed by any Java code that can access the package in which it is declared. If a class or interface type is not declared public, then it may be accessed only from within the package in which it is declared.
A member (field or method) of a reference (class, interface, or array) type or a constructor of a class type is accessible only if the type is accessible and the member or constructor is declared to permit access:
If the member or constructor is declared public, then access is permitted. All members of interfaces are implicitly public."
Compiler (or Verifier) permits to use public fields of non-public interface from another package. The test below is failed by harness under dev-jdk1.0.2-wrapper and under dev-jdk1.0.2.
> javac -d . name05601c.java
> javac -d . name05601.java
> java -verify javasoft.sqe.tests.lang.name056.name05601.name05601
failed
--------------------------name05601c.java------------------------------
package javasoft.sqe.tests.lang.name056.name05601.pckg027a;
public class name05601c {
public name05601c (int c) {
n1 = c;
nd = new name05601d (c);
}
public int n1;
public name05601d nd;
}
class name05601d implements name05601j {
name05601d (int c) {
n2 = c+i2;
}
public int n2;
}
interface name05601j {
int i2 = 6;
}
-----------------------------------------------------------------
--------------------------name05601.java-----------------------------
package javasoft.sqe.tests.lang.name056.name05601;
import java.io.PrintStream;
import javasoft.sqe.tests.lang.name056.name05601.pckg027a.name05601c;
public class name05601 {
public static void main(String argv[]) {
System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
}
public static int run(String argv[],PrintStream out) {
int a;
boolean notpass = false;
name05601c d = new name05601c (3);
try {
a = d.nd.i2;
notpass = true;
}
catch (Error ee) {
out.println (ee);
}
if ( notpass )
{
out.println("failed");
return 2;
}
return 0;
}
}
-----------------------------------------------------------------
======================================================================
- duplicates
-
JDK-4094658 Qualified access defeats access control.
- Closed
- relates to
-
JDK-4009152 Using public field of non-public class from another package is permitted.
- Closed