Microsoft KB Archive/177180

= FIX: IllegalAccessError Using Private Inherited Constructor =

Article ID: 177180

Article Last Modified on 8/25/2005

-

APPLIES TO


 * Microsoft Java Virtual Machine
 * Microsoft Visual J++ 1.1 Standard Edition
 * Microsoft Software Development Kit for Java 2.02

-



This article was previously published under Q177180



SYMPTOMS
If a class (B) inherits from a class (A) that has a private default constructor, an attempt to instantiate class (B) should result in a compiler error. The compiler shipped with Visual J++ (version 1.01.7022) does not catch this error. The Microsoft virtual machine, however, does catch this error. When the applet or application is run the following error is generated by the Microsoft virtual machine:

java.lang.IllegalAccessError: A: method V is inaccessible

NOTE: Non-Microsoft virtual machines may not throw this error. It is, however, correct behavior to do so.



RESOLUTION
Use the compiler shipped with SDK for Java 2.0x with Visual J++. You can do this by replacing the compiler file in Visual J++ with three files from the Microsoft SDK for Java. First, save a copy of the compiler (Jvc.exe) from your existing Visual J++ installation. Next, copy Jvc.exe, Jps.dll, and Msjvc.dll into your Visual J++ directory. Projects will then build using the new compiler.

The new compiler will catch this problem by generating the following error message:

error J0147: Cannot access private member 'A' in class 'A' from class 'B'



STATUS
This problem was corrected in Jvc.exe version 1.02.4337, which ships in the SDK for Java version 2.0.



Steps to Reproduce Behavior
  Using Visual J++ 1.1, create a Java Project and the following Java classes in it: public class TestError {

public static void main( String[] args ) {     boolean returnValue = true;

try {        // The compiler should flag this line as an error B obj = new B; returnValue = true; }     catch( Throwable e ) {        e.printStackTrace; returnValue = false; }

System.out.println( "Passed = " + returnValue ); } }

class A { private A {} }

class B extends A { public B {} }                        Build the Java project. You will see the above mentioned error, when you run this application.

