Uploaded image for project: 'Spring Data Neo4j'
  1. Spring Data Neo4j
  2. DATAGRAPH-1131

Fix possible ArrayIndexOutOfBoundsException in MetaDataDrivenConversionService during startup.

    Details

      Description

      When i use an abstract base class for an AttributeConverter with specific implementations i got an ArrayIndexOutOfBoundsException in MetaDataDrivenConversionService at line #77 when the converter is registered.

      The same code works with SDN 5.0.10. I didn't find any differences in MetaDataDrivenConversionService between 5.0.10 and 5.1.0, so i have no idea why it doesn't work in 5.1.0.
       

      Base class for the converter:

      public abstract class AbstractObjectToJSONStringConverter<T> implements AttributeConverter<T,String> {
      
          private final ObjectMapper mapper = new ObjectMapper();
      
          @Override
          public String toGraphProperty( final T value ) {
              if ( value == null ) {
                  return null;
              }
              String json = null;
              try {
                  json = this.mapper.writeValueAsString( value );
              }
              catch ( final IOException e ) {
                  final Logger logger = LoggerFactory.getLogger( getClass() );
                  logger.warn( e.getMessage(), e );
              }
              return json;
          }
      
          @Override
          public T toEntityAttribute( final String value ) {
              if ( value == null ) {
                  return null;
              }
              T deserialised = null;
              try {
                  deserialised = this.mapper.readValue( value, getTypeClass() );
              }
              catch ( final IOException e ) {
                  final Logger logger = LoggerFactory.getLogger( getClass() );
                  logger.warn( e.getMessage(), e );
              }
              return deserialised;
          }
      
          protected abstract Class<T> getTypeClass();
      }
      

      The implementation class:

      public class Neo4jOAuth2RefreshTokenToStringConverter extends AbstractObjectToJSONStringConverter<OAuth2RefreshToken> {
      
          @Override
          protected Class<OAuth2RefreshToken> getTypeClass() {
              return OAuth2RefreshToken.class;
          }
      }
      

      When i add an additional implements AttributeConverter<OAuth2RefreshToken,String> to the implementation class everythings works as excepected.

      Stacktrace:

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'neo4jOgmEntityInstantiatorConfigurationBean': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.neo4j.repository.config.Neo4jOgmEntityInstantiatorConfigurationBean]: Constructor threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 0
              at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:303)
              at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:284)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1307)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1153)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
              at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
              at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:848)
              at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:865)
              at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:548)
              at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400)
              at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291)
              at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103)
              at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4641)
              at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5109)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
              at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
              at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
              at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
              at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
              at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
              at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
              at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
              at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
              at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:140)
              at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
              at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
              at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
              at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.base/java.lang.reflect.Method.invoke(Method.java:564)
              at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:350)
              at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:492)
      Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.neo4j.repository.config.Neo4jOgmEntityInstantiatorConfigurationBean]: Constructor threw exception; nested exception is java.lang.ArrayIndexOutOfBoundsException: 0
              at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184)
              at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117)
              at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:299)
              ... 45 common frames omitted
      Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
              at org.springframework.data.neo4j.conversion.MetaDataDrivenConversionService.addWrappedConverter(MetaDataDrivenConversionService.java:77)
              at org.springframework.data.neo4j.conversion.MetaDataDrivenConversionService.<init>(MetaDataDrivenConversionService.java:52)
              at org.springframework.data.neo4j.repository.config.Neo4jOgmEntityInstantiatorConfigurationBean.lambda$new$0(Neo4jOgmEntityInstantiatorConfigurationBean.java:39)
              at org.springframework.beans.factory.ObjectProvider.getIfUnique(ObjectProvider.java:122)
              at org.springframework.data.neo4j.repository.config.Neo4jOgmEntityInstantiatorConfigurationBean.<init>(Neo4jOgmEntityInstantiatorConfigurationBean.java:39)
              at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
              at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

        Attachments

          Activity

            People

            • Assignee:
              michael.simons Michael Simons
              Reporter:
              torsten.kuhnhenne Torsten Kuhnhenne
              Last updater:
              Mark Paluch
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: