aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1533600 - in /aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl: ProxyManagerActivator.java weaving/ProxyWeavingHook.java
Date Fri, 18 Oct 2013 19:30:39 GMT
Author: dkulp
Date: Fri Oct 18 19:30:39 2013
New Revision: 1533600

URL: http://svn.apache.org/r1533600
Log:
[ARIES-1126] Prevent an NPE in ProxyWeavingHook and allow a setting to bypass it completely

Modified:
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java
    aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/ProxyWeavingHook.java

Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java?rev=1533600&r1=1533599&r2=1533600&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/ProxyManagerActivator.java
Fri Oct 18 19:30:39 2013
@@ -18,8 +18,6 @@
  */
 package org.apache.aries.proxy.impl;
 
-import java.util.Dictionary;
-import java.util.Hashtable;
 
 import org.apache.aries.proxy.ProxyManager;
 import org.osgi.framework.BundleActivator;
@@ -55,14 +53,7 @@ public class ProxyManagerActivator imple
         //if ASM is available then we should also try weaving
         Class<?> cls = Class.forName("org.apache.aries.proxy.impl.weaving.ProxyWeavingHook",
         		true, ProxyManagerActivator.class.getClassLoader());
-        Dictionary<String,String> props = new Hashtable<String,String>();
-        // SubsystemResource.java also uses this constant. 
-        //   While it could be turned into a static final constant, note that this
-        //   is also a non-standard workaround in the absence of a solution in the spec.

-        // See the associated OSGi spec bug. 
-        props.put("osgi.woven.packages", "org.apache.aries.proxy.weaving,org.apache.aries.proxy");
-        context.registerService("org.osgi.framework.hooks.weaving.WeavingHook",
-            cls.getConstructor(BundleContext.class).newInstance(context), props);
+        cls.getConstructor(BundleContext.class).newInstance(context);
       } catch (Throwable t) {
         //We don't care about this, we just won't have registered the hook
       }

Modified: aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/ProxyWeavingHook.java
URL: http://svn.apache.org/viewvc/aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/ProxyWeavingHook.java?rev=1533600&r1=1533599&r2=1533600&view=diff
==============================================================================
--- aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/ProxyWeavingHook.java
(original)
+++ aries/trunk/proxy/proxy-impl/src/main/java/org/apache/aries/proxy/impl/weaving/ProxyWeavingHook.java
Fri Oct 18 19:30:39 2013
@@ -19,6 +19,8 @@
 package org.apache.aries.proxy.impl.weaving;
 
 import java.util.ArrayList;
+import java.util.Dictionary;
+import java.util.Hashtable;
 import java.util.List;
 import java.util.regex.Pattern;
 
@@ -33,6 +35,7 @@ import org.osgi.framework.BundleContext;
 import org.osgi.framework.hooks.weaving.WeavingException;
 import org.osgi.framework.hooks.weaving.WeavingHook;
 import org.osgi.framework.hooks.weaving.WovenClass;
+import org.osgi.framework.wiring.BundleWiring;
 import org.osgi.util.tracker.ServiceTracker;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,20 +63,34 @@ public final class ProxyWeavingHook impl
   private final ServiceTracker controllers;
 
   public ProxyWeavingHook(BundleContext context) {
-    enabled = parseMatchers(context != null ? context.getProperty(WEAVING_ENABLED_CLASSES)
: null, WEAVING_ENABLED_CLASSES_DEFAULT);
+    String enabledProp = context != null ? context.getProperty(WEAVING_ENABLED_CLASSES) :
null;
+    enabled = parseMatchers(enabledProp, WEAVING_ENABLED_CLASSES_DEFAULT);
     disabled = parseMatchers(context != null ? context.getProperty(WEAVING_DISABLED_CLASSES)
: null, WEAVING_DISABLED_CLASSES_DEFAULT);
     controllers = new ServiceTracker(context, ProxyWeavingController.class.getName(), null);
     controllers.open();
+    
+    if (!"none".equals(enabledProp)) {
+        Dictionary<String,String> props = new Hashtable<String,String>();
+        // SubsystemResource.java also uses this constant. 
+        //   While it could be turned into a static final constant, note that this
+        //   is also a non-standard workaround in the absence of a solution in the spec.

+        // See the associated OSGi spec bug. 
+        props.put("osgi.woven.packages", "org.apache.aries.proxy.weaving,org.apache.aries.proxy");
+        context.registerService("org.osgi.framework.hooks.weaving.WeavingHook", this, props);
+    }
   }
 
   public final void weave(WovenClass wovenClass) {
+    BundleWiring bw = wovenClass.getBundleWiring();
     
-    Bundle b = wovenClass.getBundleWiring().getBundle();
-    
-    if(b.getBundleId() == 0 || 
-        b.getSymbolicName().startsWith("org.apache.aries.proxy") ||
-        b.getSymbolicName().startsWith("org.apache.aries.util")) {
-      return;
+    if (bw != null) {
+        Bundle b = bw.getBundle();
+        
+        if(b.getBundleId() == 0 || 
+            b.getSymbolicName().startsWith("org.apache.aries.proxy") ||
+            b.getSymbolicName().startsWith("org.apache.aries.util")) {
+          return;
+        }
     }
 
     if (!isEnabled(wovenClass.getClassName()) || isDisabled(wovenClass.getClassName())) {



Mime
View raw message