Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8169329

ctor can have protected and private modifiers at once

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
      Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

      FULL OS VERSION :
      Darwin mac-esxi-38 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      According the JVM specification (4.5): "...each field of a class may have at most one of its ACC_PUBLIC, ACC_PRIVATE, and ACC_PROTECTED flags set (JLS §8.3.1)..."
      However, JVM loads classes declaring protected+private method without any errors.

      It can be observed on the example below.
      This example provides runtime with the class testInitFlags_2C.j with protected+private ctor and the class Test.java which tries to instantiate testInitFlags_2C. The class testInitFlags_2C was written in Jasmin (see http://jasmin.sourceforge.net)

      THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

      THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      $ java -jar jasmin.jar testInitFlags_2C.j
      $ javac Test.java
      $ java Test


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected: testInitFlags_2C won't be instantiated and ClassFormatError (or VerifyError) will be thrown
      Actual: testInitFlags_2C is loaded without any errors; IllegalAccessException is thrown when protected&private ctor is called
      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      testInitFlags_2C.j

        .class public testInitFlags_2C
        .super java/lang/Object
        ;
        ; standard initializer
        .method protected private <init>()V
           aload_0
           invokenonvirtual java/lang/Object/<init>()V
           return
        .end method

      --------------------8<--------------------

      Test.java

      public class Test {

          public static void main(String[] args) {

              try {
                  Class cl = Class.forName("testInitFlags_2C");
                  cl.newInstance();
                  System.out.println("FAILED: class loaded and instantiated");
              } catch (ClassFormatError e) {
                  System.out.println("caught ClassFormatError (expected)");
              } catch (Throwable e) {
                  System.out.println("caught " + e);
              }
          }
      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              fmatte Fairoz Matte
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: