• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

IllegalAccessError and Classloaders.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package bar;
public class Foo {
protected void doit() {
StaticClass.doit1();
}
}

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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic