Facing Junits issue BundleContext bundleContext = FrameworkUtil.getBundle(X.class).getBundleContext();
Hi All,
I am facing some issues in writing Junits for this specific line BundleContext bundleContext = FrameworkUtil.getBundle(RunModeUtils.class).getBundleContext(); where I am getting nullPointerException and when I debug the code for getBundle() method, I observed cl is the reference of LauncherAppClassLoader and inside LauncherAppClassLoader we have defaultdomain object where I am getting this error ProtectionDomain (null <no signer certificates>)
sun.misc.Launcher$AppClassLoader@18b4aac2
<no principals>
null
So, in the if statement cl is not reference of BundleReference and therefore giving value as Null. How to resolve this issue? Can you please suggest?
public static Bundle getBundle(final Class<?> classFromBundle) {
// We use doPriv since the caller may not have permission
// to call getClassLoader.
Object cl = AccessController.doPrivileged(new PrivilegedAction<Object>() {
public Object run() {
return classFromBundle.getClassLoader();
}
});
if (cl instanceof BundleReference) {
return ((BundleReference) cl).getBundle();
}
return null;
}
