This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes IllegalAccessError and Classloaders. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "IllegalAccessError and Classloaders." Watch "IllegalAccessError and Classloaders." New topic

IllegalAccessError and Classloaders.

Jason Pepper

Joined: Oct 15, 2005
Posts: 9
package bar;
public class Foo {
protected void doit() {

package bar;
final class StaticClass {
static void doit1() {


StaticClass is in a higher classloader than class Foo. When I call doit() on a foo object I get an IIlegalAccessError.. Whats going on because my IDE
did not complain about this and usually something like this should be caught
at compile time which makes me suspect that its a classloader issue.

Can Foo access a package leve method of package level class defined in a higher class loader?
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
When you say StaticClass is in a higher classloader, you mean it's defined in the parent classloader (or parent of parent, etc) of Foo's classloader? Then that should not be a problem. I suspect your problem is that the method doit() (not doit1()) is protected, and you're now accessing it from outside the package. Try calling setAccessible(true) on the Method object, before calling invoke().

If that doesn't work, examine the stack trace carefully. Is it complaining about being unable to access doit(), or doit1()? If you're not sure, post the stack trace here.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: IllegalAccessError and Classloaders.
jQuery in Action, 3rd edition