Skip to content

Commit

Permalink
Fix for JERSEY-1404
Browse files Browse the repository at this point in the history
Change-Id: Id3df1a27664caaeb594e74b9f67b4d261cf54565
  • Loading branch information
japod committed Sep 6, 2012
1 parent 376967b commit 7557f55
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ examples/helloworld-pure-jax-rs/nb-configuration.xml
examples/helloworld/nb-configuration.xml
examples/osgi-http-service/bundle/nb-configuration.xml
examples/osgi-http-service/functional-test/nb-configuration.xml
tests/e2e/nb-configuration.xml
tests/e2e/nb-configuration.xml
core-server/nb-configuration.xml
tests/integration/servlet-tests/nb-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleReference;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.SynchronousBundleListener;

/**
Expand Down Expand Up @@ -105,7 +106,10 @@ public static synchronized OsgiRegistry getInstance() {
if (instance == null) {
final ClassLoader classLoader = ReflectionHelper.class.getClassLoader();
if (classLoader instanceof BundleReference) {
instance = new OsgiRegistry(classLoader);
BundleContext context = FrameworkUtil.getBundle(OsgiRegistry.class).getBundleContext();
if (context != null) { // context could be still null in GlassFish
instance = new OsgiRegistry(context);
}
}
}
return instance;
Expand Down Expand Up @@ -337,15 +341,12 @@ public Class<?> classForNameWithException(final String className) throws ClassNo

/**
* Creates a new OsgiRegistry instance bound to a particular OSGi runtime.
* The only parameter must be an instance of a {@link BundleReference}.
* The parameter is typed as an Object to protect callers from having
* to load OSGi classes directly.
* The only parameter must be an instance of a {@link BundleContext}.
*
* @param bundleReference must be a non-null instance of a BundleReference
* @param bundleContext must be a non-null instance of a BundleContext
*/
private OsgiRegistry(Object bundleReference) {
BundleReference br = (BundleReference)bundleReference;
bundleContext = br.getBundle().getBundleContext();
private OsgiRegistry(BundleContext bundleContext) {
this.bundleContext = bundleContext;
}

/**
Expand Down

0 comments on commit 7557f55

Please sign in to comment.