java.lang.ArrayIndexOutOfBoundsException: 0

Spring JIRA | Wizard Zhang | 2 years ago
  1. 0

    This is the Class of entity used to save to mongodb. {code:title=ClassC.java|borderStyle=solid} public class ClassC extends ClassA { private ClassB b; public ClassB getB() { return b; } public void setB(ClassB b) { this.b = b; } } class ClassA { private String name; private ClassD dObject; public String getName() { return name; } public void setName(String name) { this.name = name; } public ClassD getdObject() { return dObject; } public void setdObject(ClassD dObject) { this.dObject = dObject; } } class ClassB extends ClassA { } class ClassD { private TreeMap<String, TreeMap<String, String>> map = new TreeMap<>(); public TreeMap<String, TreeMap<String, String>> getMap() { return map; } public void setMap(TreeMap<String, TreeMap<String, String>> map) { this.map = map; } } {code} This is the call entry: {code} // handle this correctly somewhere // @Autowired // private MongoOperations mongoTemplate; ClassC cObject = new ClassC(); cObject.setName("Jon"); try { mongoTemplate.save(cObject, "c"); } catch (Exception e) { e.printStackTrace(); } {code} Exception caught as below: {code} java.lang.ArrayIndexOutOfBoundsException: 0 at org.springframework.data.util.ParameterizedTypeInformation.getComponentType(ParameterizedTypeInformation.java:147) at org.springframework.data.util.TypeDiscoverer.getActualType(TypeDiscoverer.java:292) at org.springframework.data.util.ParentTypeAwareTypeInformation.getActualType(ParentTypeAwareTypeInformation.java:29) at org.springframework.data.mapping.model.AbstractPersistentProperty.getPersistentEntityType(AbstractPersistentProperty.java:125) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:469) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:181) at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141) at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67) at org.springframework.data.mongodb.core.MongoTemplate.getPersistentEntity(MongoTemplate.java:1831) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:829) {code} I got the same issues on both *spring-data-mongodb-1.5.0-RELEASE.jar* and *spring-data-mongodb-1.5.2-RELEASE.jar*. Below is some of my investigation, maybe helpful. It seems something unsafe in *spring-data-commons-1.8.0-RELEASE.jar* and *spring-data-commons-1.8.2-RELEASE.jar*. It seems that TreeMap has something different to HashMap, such as *private transient EntrySet entrySet = null;*, which causes returning empty Type array to emit ArrayIndexOutOfBoundsException. May I know why the author treats Map as normal entity Type to traverse every field inside? Normally Map and List only used as container.

    Spring JIRA | 2 years ago | Wizard Zhang
    java.lang.ArrayIndexOutOfBoundsException: 0
  2. 0

    This is the Class of entity used to save to mongodb. {code:title=ClassC.java|borderStyle=solid} public class ClassC extends ClassA { private ClassB b; public ClassB getB() { return b; } public void setB(ClassB b) { this.b = b; } } class ClassA { private String name; private ClassD dObject; public String getName() { return name; } public void setName(String name) { this.name = name; } public ClassD getdObject() { return dObject; } public void setdObject(ClassD dObject) { this.dObject = dObject; } } class ClassB extends ClassA { } class ClassD { private TreeMap<String, TreeMap<String, String>> map = new TreeMap<>(); public TreeMap<String, TreeMap<String, String>> getMap() { return map; } public void setMap(TreeMap<String, TreeMap<String, String>> map) { this.map = map; } } {code} This is the call entry: {code} // handle this correctly somewhere // @Autowired // private MongoOperations mongoTemplate; ClassC cObject = new ClassC(); cObject.setName("Jon"); try { mongoTemplate.save(cObject, "c"); } catch (Exception e) { e.printStackTrace(); } {code} Exception caught as below: {code} java.lang.ArrayIndexOutOfBoundsException: 0 at org.springframework.data.util.ParameterizedTypeInformation.getComponentType(ParameterizedTypeInformation.java:147) at org.springframework.data.util.TypeDiscoverer.getActualType(TypeDiscoverer.java:292) at org.springframework.data.util.ParentTypeAwareTypeInformation.getActualType(ParentTypeAwareTypeInformation.java:29) at org.springframework.data.mapping.model.AbstractPersistentProperty.getPersistentEntityType(AbstractPersistentProperty.java:125) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:469) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470) at org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427) at org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572) at org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295) at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:181) at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141) at org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67) at org.springframework.data.mongodb.core.MongoTemplate.getPersistentEntity(MongoTemplate.java:1831) at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:829) {code} I got the same issues on both *spring-data-mongodb-1.5.0-RELEASE.jar* and *spring-data-mongodb-1.5.2-RELEASE.jar*. Below is some of my investigation, maybe helpful. It seems something unsafe in *spring-data-commons-1.8.0-RELEASE.jar* and *spring-data-commons-1.8.2-RELEASE.jar*. It seems that TreeMap has something different to HashMap, such as *private transient EntrySet entrySet = null;*, which causes returning empty Type array to emit ArrayIndexOutOfBoundsException. May I know why the author treats Map as normal entity Type to traverse every field inside? Normally Map and List only used as container.

    Spring JIRA | 2 years ago | Wizard Zhang
    java.lang.ArrayIndexOutOfBoundsException: 0
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Cassandra ArrayIndexOutOfBoundsException

    Stack Overflow | 3 years ago | user3087110
    java.lang.RuntimeException: java.lang.ArrayIndexOutOfBoundsException: 0

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.ArrayIndexOutOfBoundsException

      0

      at org.springframework.data.util.ParameterizedTypeInformation.getComponentType()
    2. Spring Data Core
      AbstractMappingContext$PersistentPropertyCreator.doWith
      1. org.springframework.data.util.ParameterizedTypeInformation.getComponentType(ParameterizedTypeInformation.java:147)
      2. org.springframework.data.util.TypeDiscoverer.getActualType(TypeDiscoverer.java:292)
      3. org.springframework.data.util.ParentTypeAwareTypeInformation.getActualType(ParentTypeAwareTypeInformation.java:29)
      4. org.springframework.data.mapping.model.AbstractPersistentProperty.getPersistentEntityType(AbstractPersistentProperty.java:125)
      5. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:469)
      6. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427)
      6 frames
    3. Spring Core
      ReflectionUtils.doWithFields
      1. org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572)
      1 frame
    4. Spring Data Core
      AbstractMappingContext$PersistentPropertyCreator.doWith
      1. org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295)
      2. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470)
      3. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427)
      3 frames
    5. Spring Core
      ReflectionUtils.doWithFields
      1. org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572)
      1 frame
    6. Spring Data Core
      AbstractMappingContext$PersistentPropertyCreator.doWith
      1. org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295)
      2. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470)
      3. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427)
      3 frames
    7. Spring Core
      ReflectionUtils.doWithFields
      1. org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572)
      1 frame
    8. Spring Data Core
      AbstractMappingContext$PersistentPropertyCreator.doWith
      1. org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295)
      2. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.createAndRegisterProperty(AbstractMappingContext.java:470)
      3. org.springframework.data.mapping.context.AbstractMappingContext$PersistentPropertyCreator.doWith(AbstractMappingContext.java:427)
      3 frames
    9. Spring Core
      ReflectionUtils.doWithFields
      1. org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:572)
      1 frame
    10. Spring Data Core
      AbstractMappingContext.getPersistentEntity
      1. org.springframework.data.mapping.context.AbstractMappingContext.addPersistentEntity(AbstractMappingContext.java:295)
      2. org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:181)
      3. org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:141)
      4. org.springframework.data.mapping.context.AbstractMappingContext.getPersistentEntity(AbstractMappingContext.java:67)
      4 frames
    11. Spring Data MongoDB - Core
      MongoTemplate.save
      1. org.springframework.data.mongodb.core.MongoTemplate.getPersistentEntity(MongoTemplate.java:1831)
      2. org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:829)
      2 frames