Details
-
Type:
New Feature
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: 2.0.0-RC4, 2.2.0
-
Fix Version/s: 2.5.0
-
Component/s: Native Test Container
-
Labels:None
-
Environment:Junit 4.8,
Maven 3
Description
native container runner starts with a dependency filled system classloader. This leads to hard tracable problems with (mostly hybrid) bundles which using first the system classloader for reflection. E.g. the combination of eclipse link with the corresponding apache aries adapter behave different in a pax exam native container as in a blank felix.
(may be related to PAXEXAM-81)
Issue Links
| This issue is related from: | ||||
| PAXEXAM-301 | Implement Forked Container |
|
|
|

It is true that some tests may behave differently or even fail when running in the Native container compared to the Pax Runner container. I had a similar effect in a test with OpenJPA 2.1.0 and Aries JPA 0.3.
This is not necessarily a defect in Pax Exam. When you move from the plain old classpath to modular development with OSGi, you will discover that some libraries break because they mess around with Class.forName() which is a no-go in OSGi and a bad idea anyway.
Similarly, when you move from Pax Runner Container to Native Container, the OSGi framework is no longer running in its own VM, there are some bits of Pax Exam that use the official OSGi FrameworkFactory API to launch an embedded framework. In this scenario, the system classloader necessarily contains some other application classes on top of the OSGi framework classes.
Any OSGi framework should take care to set up boot delegation and the parent classloader for bundle classloaders correctly. Equinox gives you some extra control by means of osgi.* system properties.
But even so, there is no way to protect you from bundles in your system calling ClassLoader.getSystemClassloader() directly and thus bypassing the classloader hierarchy carefully set up by the framework.
This is what happens in Aries JPA 0.3 where the BundleDelegatingClassLoader which should load entity classes from application bundles inadvertently works with parent delegation, using the system classloader as its parent, so if you use your entity classes in your Pax Exam test, they will be loaded from the application classloader and not from the bundle classloader.
This class has been reworked substantially on Aries trunk, so I hope this issue will be fixed with the next Aries JPA release.