Issue
Our architecture combines Spring with MongoDB. We usually do not have any issues with saving/editing and reading custom objects. Lately we have ran a few modifications in which we started getting the following errors
java.lang.StackOverflowError
at java.util.Collections.emptyList(Collections.java:2959)
at org.springframework.data.util.TypeDiscoverer.getTypeArguments(TypeDiscoverer.java:442)
at org.springframework.data.util.ClassTypeInformation.getTypeArguments(ClassTypeInformation.java:40)
at org.springframework.data.util.TypeDiscoverer.getActualType(TypeDiscoverer.java:288)
at org.springframework.data.util.ClassTypeInformation.getActualType(ClassTypeInformation.java:40)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.addCustomTypeKeyIfNecessary(MappingMongoConverter.java:650)
Or
java.lang.StackOverflowError
at sun.misc.Unsafe.getObject(Native Method)
at sun.misc.Unsafe.getObject(Unsafe.java:231)
at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:19)
at java.lang.reflect.Field.get(Field.java:358)
at org.springframework.util.ReflectionUtils.getField(ReflectionUtils.java:118)
at org.springframework.data.mapping.model.BeanWrapper.getProperty(BeanWrapper.java:133)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$3.doWithPersistentProperty(MappingMongoConverter.java:382)
Before I'm adding all the major classes that combines our architecture I wonder whether any of you have previously encountered these kind of exceptions?
Solution
Apparently I can not add logger to my data objects,
when I removed the logger it started working again
protected final Log logger = LogFactory.getLog(getClass());
Be careful when using loggers in your data object in MongoDB
It seems that using @Transient should signal MongoDB driver not to persist the logger variable
Answered By - Uri Lukach
Answer Checked By - David Goodson (JavaFixing Volunteer)