JDK-4007893 : Using private method from another class.
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 1.0.2,1.1,1.1.1
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.4,solaris_2.6
  • CPU: sparc
  • Submitted: 1996-10-08
  • Updated: 1997-07-22
  • Resolved: 1997-07-22
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description

Name: vsC45997			Date: 10/08/96


The section "12.3.3 Resolution of Symbolic References" of The Java Language
Specification contains the following:

"This error may be thrown at any point in the program that uses a symbolic reference to the type, directly or indirectly:

    IllegalAccessError: A symbolic reference has been encountered that 
    specifies a use or assignment of a field, or invocation of a method,
    or creation of an instance of a class, to which the code containing the 
    reference does not have access because the field or method was declared 
    private, protected, or default access (not public), or because the class
    was not declared public. This can occur, for example, if a field that is
    originally declared public is changed to be private after another class
    that refers to the field has been compiled (��13.4.6)." 

Verifier permits to use the private method from another class. 

> javac -d . exec00502.java
> javac -d . exec00502a.java
> java -verify javasoft.sqe.tests.lang.exec005.exec00502.exec00502
failed


--------------------------exec00502------------------------------
package javasoft.sqe.tests.lang.exec005.exec00502;
import java.io.PrintStream;
public class exec00502 extends exec00502a {
  public static void main(String argv[])
  {
     System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
  }
  public static int run(String argv[],PrintStream out) {
    try {
      prc (6);
    }
    catch (Error e) {
      out.println ("er2 " + e);
      return 0;
    }
    out.println ("failed");
    return 2;
  }
}
class exec00502a  {
  int a = 5;
  static int prc (int i) {
    return i;
  }
}
-----------------------------------------------------------------
--------------------------exec00502a-----------------------------
package javasoft.sqe.tests.lang.exec005.exec00502;
public class exec00502a  {
  int a = 5;
  private static int prc (int i) {
    return i;
  }
}
-----------------------------------------------------------------

======================================================================

Comments
EVALUATION This is a holdover of the formerly broken compiler, than when run -O, would inline private methods even though it shouldn't. Downloaded methods will, indeed, get the verification error. Unfortunately, for historical purposes, we cannot yet cause this error for locally compiled classes. Since this only "looks like a security violation", but isn't really one, I'm downgrading it appropriately.
11-06-2004