Osgi中碰到ArrayStoreException问题

在Gemini-blueprint中进行proxyinterface操作时遇到ArrayStoreException错误,通过检查ClassLoader并确保其一致性解决了问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在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 an ArrayStoreException:

     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加载一致.



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值