[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] Class loader, class space, protection domai, package private things and fragments

Just to clarify:

- the access happens from within a JUnit test defined in a fragment

- the JUnit test can *access* the package private methods without problems (in OSGi and outside)

- Mockito mock/spy runs fine in a non-OSGi environment

- Mockity mock/spy runs fine in an Eclipse JUnit Plug-in test environment

- Mockity mock/spy fails in OSGi-Tycho-Surefire environment


On 2014-07-22 22:18:51 +0000, Neil Bartlett said:

This is probably because package-private accessibility in the JVM is based on the concept of âruntime packagesâ.

A runtime package is a package loaded by a particular classloader. If some classes have the same package name but are loaded by a different classloader then they are NOT part of the same runtime package, so do not have access to the package-private members and would throw IllegalAccessError.

Very few people seem to know about this area of the Java specification! It means that the javac compiler actually has no idea whether some code has access to a private-package member, since it doesnât know how you will arrange your classloaders at runtime. Of course in OSGi we have multiple classloaders. Mockito would probably fail in the same way outside of OSGi if you loaded it in a different classloader from the classes it is trying to mockâ


On 22 July 2014 at 22:52:00, Gunnar Wagenknecht (gunnar@xxxxxxxxxxxxxxx) wrote:

Hi Tom!Â

On 2014-07-18 19:09:02 +0000, Thomas Watson said:Â

> Are your troubles when you run the fragment in the Equinox/OSGiÂ

> environment or is it when using Mockito/CGLIB outside of an OSGiÂ

> environment? ÂIf it is the later then are you running into issues withÂ

> signing? ÂOr perhaps you could clarify the issue you are running intoÂ

> because I just realized that it is not clear to me ;-)Â

I fixed the problems with signing upstream in cglib. :) Hopefully itÂ

ends up in Mockito one day.Â

But the other problem I have with Mockito is that it can't mock packageÂ

private methods in an OSGi environment. It works outside of OSGi. Thus,Â

when a class is defined in a bundle and has package private methods,Â

those methods can be accessed in the test fragment. However, mockingÂ

those fails in OSGi. Oh and to make the problem even more complex, itÂ

does not fail when run as "JUnit Plug-in Test" from within Eclipse butÂ

when run as Tycho Surefire test from within a Maven Tycho build. But asÂ

soon as I make the methods protected it works.Â



Gunnar WagenknechtÂ



equinox-dev mailing listÂ


To change your delivery options, retrieve your password, or unsubscribe from this list, visitÂ



Gunnar Wagenknecht