本文介绍了ArrayOutOfBoundsException:asm.ClassReader.readClass(未知来源)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下依赖关系的层次结构:

I have a hierarchy with the following dependencies:

Base(Timer timer)

    Timer(PublisherService service, BaseDao userDao, DataProcessor processor)

中还有其他依赖项DataProcessor 但是我不会那么远,因为我的错误似乎发生得更早。与该依赖图相对应,我有以下Spring配置:

There are additional dependencies within DataProcessor but I will not go that far because it seems my error occurs a lot earlier. In correspondence with that dependency graph, I have the following Spring configuration:

<bean id="base" class="com.apps.consumer.Base">
    <constructor-arg name="timer" ref="consumerTimerTask"/>
</bean>

<bean id="consumerTimerTask" class="com.apps.consumer.ConsumerTimerTask">
    <constructor-arg name="service" ref="tradePublisherService"/>
    <constructor-arg name="userDao" ref="userDao"/>
    <constructor-arg name="consumerDataProcessor" ref="consumerDataProcessor"/>
</bean>

<bean id="tradePublisherService" class="com.apps.consumer.common.TradePublisherService"/>

<bean id="userDao" class="com.apps.dao.UserDao"/>

<bean id="consumerDataProcessor" class="com.apps.consumer.ConsumerDataProcessor">
    <!-- Additional constructor-args here for this guy -->
</bean>

在我的应用程序的顶层,我将运行:

At the top level of my application, I will run:

ApplicationContext context = new ClassPathXmlApplicationContext("spring-configuration.xml");

Base consumerBase = context.getBean("base", Base.class);

当我按照调试时发现计时器已成功初始化。 。 。有些。在计时器完全解析并注入 Base 之前,我得到以下内容:

As I follow the debugging I find that the Timer is initialized successfully. . .somewhat. Before the Timer is fully resolved and injected into the Base I get back the following:

java.lang.ArrayIndexOutOfBoundsException: 3145
at org.springframework.asm.ClassReader.readClass(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.asm.ClassReader.accept(Unknown Source)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.visitConstructor(LocalVariableTableParameterNameDiscoverer.java:123)
at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:89)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:984)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:886)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:600)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:140)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:984)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:886)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:479)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.apps.Main.contextInitialized(Main.java:39)

我正追溯到 Main 这是我的堆栈跟踪中唯一的类。

I'm tracing it back as far as Main which is the only class in the stack trace that is mine.

删除Java和XML中的所有三个构造函数参数可以解决问题,但是引入3个构造函数参数中的任何一个都会将其重新引出。例如,对于 DataProcessor ,依赖图确实更深一些,但即使我只使用 BaseDao 作为构造函数args ,它本身没有依赖关系,我会得到这个错误。

Removing all three constructor parameters in both Java and XML resolves the issue however introducing any one of the 3 constructor arguments brings it back. The dependency graph does go a little deeper for DataProcessor for example, but even if I just use BaseDao as the constructor args, which itself has no dependencies, I will get this error.

知道这里发生了什么吗?我已经尝试了构造函数args的各种排列,创建了新的接口实现,以防我现有的东西导致问题冒出来,几乎所有的一切都不好意思只是从头开始重写这个。

Any idea what is going on here? I have tried various permutations of constructor args, creating new interface implementations in case something in my existing ones was causing the issue to bubble up, pretty much everything shy of just rewriting this from scratch more carefully.

编辑:

public class Base {
    private TimerTask consumerTimerTask;

    private static Logger logger = LoggerFactory.getLogger(Base.class);

    public Base(TimerTask timer) {
        this.consumerTimerTask = timer;
    }

    /**
     * Initialize the timer.
     * @throws Exception
     */
    public void initialize() throws Exception {
        final int updateFrequency = 10000;

        // Once all fields have been generated and prefs read, initialize the update process every number of seconds.
        final Timer updateTimer = new Timer();

        updateTimer.scheduleAtFixedRate(this.consumerTimerTask, 0, updateFrequency);

        logger.info("Base initialized successfully!");
    }
}


推荐答案

代码是继承的,我忽略了以下依赖项的版本:

Being that the code was inherited, I overlooked the version of the following dependency:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
</dependency>

设置< spring.version> 4.2.4.RELEASE< / spring .version> 解决了这个问题。

这篇关于ArrayOutOfBoundsException:asm.ClassReader.readClass(未知来源)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 08:28