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

(reflect) poor diagnostic for IllegalAccessException for package-private field

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.0, 5.0
    • core-libs

      Date: Fri, 25 Jul 2003 02:46:40 -0700 (PDT)
      From: Olivier Lefevre <###@###.###>
      Subject: Odd compiler message
      To: Neal M Gafter <###@###.###>
      Reply-to: ###@###.###
      Message-id: <###@###.###>

      I was trying to access via reflection a public field in a class
      that had nomodifier and thus was package-private, from a class
      (its parent) in another package. The compiler said:

        java.lang.IllegalAccessException: Class <caller> can not access
        a member of class <target> with modifiers "public"

      Try as I might, I could not make heads or tails of that. So I tried
      accessing the field "manually" instead, hoping to get a different
      message, and indeed I got

        <target> is not public in <package>; cannot be accessed from
        outside package

        <field> in <target> is not defined in a public class or interface;
        cannot be accessed from outside package

      Now _that_ made sense! The problem happened because the
      parent was once in the same package but was later moved
      out. In general, woulnd't it be a desirable goal to get
      the same error message (although not the same stack trace,
      of course) whether one is trying to access a field directly
      or through reflection?

      Best,

      -- O.L.

            Unassigned Unassigned
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: