• Post Reply Bookmark Topic Watch Topic
  • New Topic

VerifyError: Bad access to protected data  RSS feed

 
Thomas Bauer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!

I just got my first VerifyError - wow!

Here is my immature code:


This works fine when using one ClassLoader. However if MyClass is loaded in the parent classloader and SubClass in the child classloader (of the parent), the child classloader complains with a VerifyError: Bad access to protected data

Any hints?
thnx

Pauli
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As written, SubClass is allowed to call MyClass.myMethod() in doSomething() only because the two classes are in the same package. The rules for "protected" state that you can call a protected method only on a reference that is at least the same type as the calling class -- i.e., SubClass could call SubClass.myMethod(), or myMethod() on a "SubSubClass" class, but not on an instance of MyClass or on any other class. The only reason the access is allowed is because all classes in a package can access each other's protected methods.

Once two classes are loaded by two different ClassLoaders, they're not technically in the same package anymore; see VM Specification. Therefore, this "back door" disappears, and you're bound by the standard definition of "protected" across packages.

The long and short of it is that a method like "doSomething()" must be in "MyClass" or it's not going to work.
[ April 03, 2006: Message edited by: Ernest Friedman-Hill ]
 
Thomas Bauer
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey!

Thanks for your quick reply. I thought about something like this but was not sure - thanks for the pointer to the spec!

regards,

Pauli
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!