Osgi中碰到ArrayStoreException问题

来源:互联网 发布:python 数据拟合曲线 编辑:程序博客网 时间:2024/04/29 14:25

在Gemini-blueprint中做proxy interface时,出现了这个错误。

先看JavaDoc的提示:

Thrown to indicate that an attempt has been made to store the wrong type of object into an array of objects. For example, the following code generates anArrayStoreException:

     Object x[] = new String[3];     x[0] = new Integer(0);

再看看代码

org.eclipse.gemini.blueprint.service.importer.support.AbstractServiceProxyCreator

 public ProxyPlusCallback createServiceProxy(ServiceReference reference) {                List advices = new ArrayList(4);                // 1. the ServiceReference-like mixin                Advice mixin = new ImportedOsgiServiceProxyAdvice(reference);                advices.add(mixin);                // 2. publication of bundleContext (if there is any)                // TODO: make this configurable (so it can be disabled)                advices.add(invokerBundleContextAdvice);                // 3. TCCL handling (if there is any)                Advice tcclAdvice = determineTCCLAdvice(reference);                if (tcclAdvice != null)                        advices.add(tcclAdvice);                // 4. add the infrastructure proxy                // but first create the dispatcher since we need                ServiceInvoker dispatcherInterceptor = createDispatcherInterceptor(reference);                Advice infrastructureMixin = new InfrastructureOsgiProxyAdvice(dispatcherInterceptor);                advices.add(infrastructureMixin);                advices.add(dispatcherInterceptor);                return new ProxyPlusCallback(ProxyUtils.createProxy(getInterfaces(reference), null, classLoader, bundleContext,                                advices), dispatcherInterceptor);        }

ProxyUtils

public static Object createProxy(Class<?>[] classes, Object target, ClassLoader classLoader,BundleContext bundleContext, List advices) {return createProxy(classes, target, classLoader, bundleContext, (advices != null ? (Advice[]) advices.toArray(new Advice[advices.size()]) : new Advice[0]));}


AbstractServiceProxyCreator中的createproxy方法没有加入泛型约束,刚开始以为是这里可能出现bug。

后加入泛型约束

List<Advice> advices = new ArrayList<Advice>(4);

没有错误。应该不是代码的问题,而是ClassLoader的问题。因为ClassLoader的ClassDef不同,所以在ArrayList.toarray也会错误。

检查本地classloader,发现

web container 中有一个aopxxx.jar     ,在web container中的osgi container也有一个,其他细节在这里就不描述了(涉及web container和osgi container share library),至此问题定位到了。

删除其中一个 container,保持aop类的classloader加载一致.



原创粉丝点击