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

IllegalAccessException for a public field of a public class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.1.5, 1.2.0
    • core-libs
    • sparc
    • solaris_2.5



      Name: mgC56079 Date: 02/18/98



      Reflection throws an IllegalAccessException if a public field inherited from
      a non-public interface is accessed.

      Direct access works fine however.

      ----- Here is the test (Const.java) -----
      public class Const {
        public static void main(String[] args) {
          // direct access works fine
          System.out.print("Direct access: ");
          System.out.println(java.io.ObjectInputStream.STREAM_VERSION);

          // access via reflection fails
          System.out.print("Reflection: ");
          try {
            java.lang.reflect.Field f=
              java.io.ObjectInputStream.class.getField("STREAM_VERSION");
            System.out.println(f.get(null));
          }
          catch (Exception e) {
            e.printStackTrace();
          }
        }
      }
      ---- Here is the output from the test -------
      java Const
      Direct access: 5
      Reflection: java.lang.IllegalAccessException: java/io/ObjectStreamConstants
      at Const.main(Const.java:12)

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

            sliangsunw Sheng Liang (Inactive)
            mgorshen Mikhail Gorshenev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: