[FELIX-158] Add Bundle.getBundleContext() method
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@523350 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/scr/src/main/java/org/apache/felix/scr/Activator.java b/scr/src/main/java/org/apache/felix/scr/Activator.java
index 0eb1c94..69b3d0e 100644
--- a/scr/src/main/java/org/apache/felix/scr/Activator.java
+++ b/scr/src/main/java/org/apache/felix/scr/Activator.java
@@ -252,12 +252,21 @@
*/
private BundleContext getBundleContext(Bundle bundle)
{
-// try {
-// return bundle.getBundleContext();
-// } catch (Throwable t) {
-// // don't care, might be that the implementation is not yet updated
-// // to OSGi Rev 4.1
-// }
+ try
+ {
+ return bundle.getBundleContext();
+ }
+ catch ( SecurityException se )
+ {
+ // assume we do not have the correct AdminPermission[*,CONTEXT]
+ // to call this, so we have to forward this exception
+ throw se;
+ }
+ catch ( Throwable t )
+ {
+ // ignore any other Throwable, most prominently NoSuchMethodError
+ // which is called in a pre-OSGI 4.1 environment
+ }
BundleContext context = null;
for (Class clazz = bundle.getClass(); context == null && clazz != null; clazz = clazz.getSuperclass())