-
Bug
-
Resolution: Fixed
-
P2
-
1.0.2
-
1.1beta3
-
sparc
-
solaris_2.4
-
Not verified
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 class from another package. The test below is passed by harness under dev-jdk1.0.2-wrapper. If I run the test
by dev-jdk1.0.2, the test is failed.
> javac -d . name05701c.java
> javac -d . name05701.java
> java -verify javasoft.sqe.tests.lang.name057.name05701.name05701
failed
--------------------------name05701c.java------------------------------
package javasoft.sqe.tests.lang.name057.name05701.pckg027a;
public class name05701c {
public name05701c (int c) {
n1 = c;
nd = new name05701d (c);
}
public int n1;
public name05701d nd;
}
class name05701d {
name05701d (int c) {
n2 = c;
}
public int n2;
}
-----------------------------------------------------------------
--------------------------name05701.java-----------------------------
package javasoft.sqe.tests.lang.name057.name05701;
import java.io.PrintStream;
import javasoft.sqe.tests.lang.name057.name05701.pckg027a.name05701c;
public class name05701 {
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;
name05701c d = new name05701c (3);
try {
a = d.nd.n2;
notpass = true;
}
catch (Error ee) {
out.println(ee);
}
if ( notpass ) {
out.println("failed");
return 2;
}
return 0;
}
}
-----------------------------------------------------------------
======================================================================
- relates to
-
JDK-4022377 javac allows packages to call public static methods on package-private classes
-
- Closed
-
-
JDK-4009154 Using public field of non-public interface from another package is permitted.
-
- Closed
-
-
JDK-1262875 compiler and runtime both permit acces to non=public classes from other packages
-
- Closed
-
-
JDK-4016672 access to non-public class are permitted from another package
-
- Closed
-