• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

VerifyError: Bad access to protected data

 
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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
 
It's just like a fortune cookie, but instead of a cookie, it's pie. And we'll call it ... tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!