BUG: IllegalAccessError Using Private Inherited Constructor

Last reviewed: January 29, 1998
Article ID: Q177180
The information in this article applies to:
  • Microsoft Win32 Virtual Machine for Java
  • Microsoft Visual J++, version 1.1
  • SDK for Java, version 2.0

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 for Java, however, does catch this error. When the applet or application is run the following error is generated by the Virtual Machine:

   java.lang.IllegalAccessError: A: method <init>()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.0 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 version 1.02.4337, which ships in the SDK for Java version 2.0

MORE INFORMATION

Steps to Reproduce Behavior

  1. 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() {}
          }
    
    

  2. Build the Java project.

  3. You will see the above mentioned error, when you run this application.

REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/


Additional query words: protected private default constructor

Keywords : kbcode kberrmsg JVM
Technology : kbInetDev internet
Version : WINDOWS:1.1,2.0
Platform : WINDOWS
Issue type : kbbug


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.