java.lang.ArrayIndexOutOfBoundsException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • 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.
    via by Wizard Zhang,
  • 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.
    via by Wizard Zhang,
    • 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)
    No Bugmate found.