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

Regular accessibility, not reflective access

XMLWordPrintable

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      I have two classes A and B, where B extends A and A is package protected. Both classes are in the same package.

      class A
      {
            public static final String VALUE = "foo";
      }

      public class B extends A
      {
      }

      // The static constant VALUE from A is accessible through B:
      System.out.println( B.VALUE );

      // Reflective access doesn't work without making the field accessible, which is not always an option.
      // And whenever regular access is possible, reflective access should be as well from the same context.

      Class< B > clazz = ...;
      Field field = clazz.getField( "VALUE" );
      String value = (String) field.get( null );
      System.out.println( value );

      REGRESSION. Last worked in version 8u131

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Whenever regular access is possible, reflective access should be as well from the same context.

      ACTUAL -
      Reflective access doesn't work without making the field accessible, which is not always an option.

      REPRODUCIBILITY :
      This bug can be reproduced always.

        1. B.java
          0.1 kB
        2. Test.java
          0.4 kB

            mchung Mandy Chung
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: