-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
1.4.0, 5.0
-
generic
-
generic, solaris_8
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.
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.
- relates to
-
JDK-8199940 Print more information about class loaders in IllegalAccessErrors
-
- Resolved
-