• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

VerifyError: Bad access to protected data

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Are you here to take over the surface world? Because this tiny ad will stop you!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic