0

LocalDate instantiation in Springbean using Application context is throwing an ArrayIndexOutofBoundsException

package app;


import java.time.LocalDate;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ApplicationMain {

    public static void main(String[] args)  {

        ApplicationContext beanFactory = new ClassPathXmlApplicationContext(
                "spring.xml");

        LocalDate l =(LocalDate) beanFactory.getBean("localDate");
        System.out.println(l);


    }
}
---------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
                  "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
    <bean id="localDate" class="java.time.LocalDate" factory-method="now" />
</beans>

---------------------------------------------

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 52222
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.asm.ClassReader.<init>(Unknown Source)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer.inspectClass(LocalVariableTableParameterNameDiscoverer.java:112)
    at org.springframework.core.LocalVariableTableParameterNameDiscoverer.getParameterNames(LocalVariableTableParameterNameDiscoverer.java:71)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:443)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:964)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:870)
    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:562)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:871)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:423)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
    at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
    at app.ApplicationMain.main(ApplicationMain.java:13)
-------
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
Shiva Garg
  • 826
  • 9
  • 17
  • What Java version are you running on? What Java version did you use to compile your program with? What Spring version are you using? – Sotirios Delimanolis Mar 17 '15 at 20:02
  • jre / jdk 1.8.0_31 - Java version spring 3.0.1 - Spring – Shiva Garg Mar 17 '15 at 20:07
  • Do you have any conflicting spring jars in your classpath? Also, what is the spring version you are using? – Aninda Bhattacharyya Mar 17 '15 at 20:16
  • Unless I'm miscounting the line numbers, the exception is being thrown on new ClassPathXmlApplicationContext("spring.xml"), not on the instantiation of LocalDate. Is your spring.xml valid and in the right location? – tzimnoch Mar 17 '15 at 20:16
  • yes... It is at right location.. It had some code...I removed it,,, thats why line number is conflicting and moreover , It is successfully working with XMLBeanFactory , and second thing ,,,It is also working with Runtime Singleton class.. – Shiva Garg Mar 17 '15 at 20:21
  • 1
    Spring 3.0 isn't for java 1.8 especially due to the ASM version that is included which doesn't support java 8. There is a major difference between a `BeanFactory` and an `ApplicationContext`. – M. Deinum Mar 17 '15 at 20:27

1 Answers1

0

This code is working if i use Spring 4 and Java 8 .

There might be some API level restriction in Spring 3 that obstructs the instantiation of the LocalDate in springbean using the ApplicationContext / AbstarctApplicationContext

Shiva Garg
  • 826
  • 9
  • 17