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

IllegalAccessException for a public field of a public class

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 1.1.5, 1.2.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5

      Description



      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)

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: