Hello,

       As far as I could understand, you iterate between two CL. The one
from module 2 (p2.A2.class.getClassLoader()) imports javax.naming, but the
one from the activator's class (getClass().getClassLoader()) from module 3
does NOT imports javax.naming, so if you try to proxy using this last
classloader it won't be possible since p2.A2 interface extends from
javax.naming.Context.
       If this is the problem, to fix it module 3 must import javax.naming

       Hope this helps.

Cheers

On Wed, Jun 1, 2011 at 17:11, Sahoo <[email protected]> wrote:

> Hi,
>
> I am having a strange problem using dynamic proxies. I am being forced to
> import more classes than required. I have reduced it to a simple scenario as
> shown below:
>
> module 1:
> package p1;
> public interface A1 extends javax.sql.PooledConnection {
> }
>
> Export-Package: p1
> Import-Package: javax.sql
>
> module 2:
> package p2;
> public interface A2 extends javax.naming.Context, p1.A1 {
> }
>
> Export-Package: p2
> Import-Package: javax.naming, p1
>
> module 3:
> Bundle-Activator: p3.Activator
> Import-Package: p2, org.osgi.framework
>
> public class Activator implements BundleActivator {
>  public void start(BundleContext ctx) throws Exception {
>   for (ClassLoader cl : new ClassLoader[]{getClass().getClassLoader(),
> p2.A2.class.getClassLoader()}) {
>    try {
>     System.out.println(cl);
>     Object obj = Proxy.newProxyInstance(cl, new Class[]{p2.A2.class},
>                new InvocationHandler() {
>                    public Object invoke(Object proxy, Method method,
> Object[] args) throws Throwable {return null;}
>                });
>     System.out.println(obj);
>    } catch(Throwable e) {
>     e.printStackTrace();
>    }
>   } // for
>  }
>  public void stop(BundleContext ctx) throws Exception {}
> }
>
> It fails like this:
>
> 3.0
> java.lang.NoClassDefFoundError: javax.naming.Name not found by m3 [3]
>    at $Proxy0.<clinit>(Unknown Source)
>    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>    at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>    at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
>    at p3.Activator.start(Activator.java:11)
>    at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633)
>    at org.apache.felix.framework.Felix.activateBundle(Felix.java:1822)
>    at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
>    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1143)
>    at
> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
>    at java.lang.Thread.run(Thread.java:619)
> 2.0
> java.lang.NoClassDefFoundError: javax.sql.StatementEventListener not found
> by m2 [2]
>    at $Proxy1.<clinit>(Unknown Source)
>    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>    at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
>    at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
>    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
>    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
>    at p3.Activator.start(Activator.java:11)
>    at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:633)
>    at org.apache.felix.framework.Felix.activateBundle(Felix.java:1822)
>    at org.apache.felix.framework.Felix.startBundle(Felix.java:1739)
>    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1143)
>    at
> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
>    at java.lang.Thread.run(Thread.java:619)
>
> It seems to me that JVM is assuming that the defining loader of the proxy
> class can load every class that appear in the signature of methods that can
> be invoked using the proxy class. Anybody interested to debug can use the
> attached sample. Just unzip and run run.sh after editing path to Felix.
>
> Thanks,
> Sahoo
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

Reply via email to