XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • None
    • Mapping / Conversion
    • None
    • Kubuntu Linux 18.04
      Apache Maven 3.5.2
      Java 1.8.0_121

    Description

      Good day. I'm trying to upgrade a project from Spring Boot v2.0.0 to v2.1.4 using MongoDB.
      Here's the steps to replicate.

      1. Enable mongo auditing in a spring project.
      2. Add an entity with @CreatedDate, @LastModifiedDate, @CreatedBy, and @LastModifiedBy annotations.
      3. Add an embedded object as a field to that entity. That embedded object also should have the aforementioned annotations.
      4. Try saving the entity with the embedded object field having a null value by calling the MongoRepository's save() method.
      5. The error should display.

       

      I've also created a repository to replicate the issue. See below:
      https://github.com/snow-drop/spring-boot-mongo-bug

      Related links:
      https://github.com/spring-projects/spring-boot/issues/16426
      https://github.com/gznglor/spring-boot-mongo-bug
      https://github.com/spring-projects/spring-boot/issues/15851

      Here's the stack trace:

      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditBugApplication': Invocation of init method failed; nested exception is org.springframework.data.mapping.MappingException: Cannot lookup property private com.example.Address com.example.Person.address on null intermediate! Original path was: address.dateCreated on com.example.Person.org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditBugApplication': Invocation of init method failed; nested exception is org.springframework.data.mapping.MappingException: Cannot lookup property private com.example.Address com.example.Person.address on null intermediate! Original path was: address.dateCreated on com.example.Person. at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:139) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:414) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1770) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE] at com.example.AuditBugApplication.main(AuditBugApplication.java:19) [classes/:na]Caused by: org.springframework.data.mapping.MappingException: Cannot lookup property private com.example.Address com.example.Person.address on null intermediate! Original path was: address.dateCreated on com.example.Person. at org.springframework.data.mapping.PersistentPropertyAccessor.setProperty(PersistentPropertyAccessor.java:70) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.lambda$setDateProperty$1(MappingAuditableBeanWrapperFactory.java:265) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_121] at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setDateProperty(MappingAuditableBeanWrapperFactory.java:265) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setCreatedDate(MappingAuditableBeanWrapperFactory.java:198) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.auditing.AuditingHandler.lambda$touchDate$9(AuditingHandler.java:219) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at java.util.Optional.ifPresent(Optional.java:159) ~[na:1.8.0_121] at org.springframework.data.auditing.AuditingHandler.touchDate(AuditingHandler.java:219) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.auditing.AuditingHandler.lambda$touch$0(AuditingHandler.java:166) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at java.util.Optional.map(Optional.java:215) ~[na:1.8.0_121] at org.springframework.data.auditing.AuditingHandler.touch(AuditingHandler.java:163) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.auditing.AuditingHandler.markCreated(AuditingHandler.java:131) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.auditing.IsNewAwareAuditingHandler.markAudited(IsNewAwareAuditingHandler.java:83) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.lambda$onApplicationEvent$0(AuditingEventListener.java:54) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent.mapSource(MongoMappingEvent.java:90) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.onApplicationEvent(AuditingEventListener.java:54) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.onApplicationEvent(AuditingEventListener.java:32) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:402) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:359) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate.maybeEmitEvent(MongoTemplate.java:2276) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1235) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1178) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.save(SimpleMongoRepository.java:81) ~[spring-data-mongodb-2.1.6.RELEASE.jar:2.1.6.RELEASE] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121] at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61) ~[spring-data-commons-2.1.6.RELEASE.jar:2.1.6.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.1.6.RELEASE.jar:5.1.6.RELEASE] at com.sun.proxy.$Proxy62.save(Unknown Source) ~[na:na] at com.example.AuditBugApplication.onBoot(AuditBugApplication.java:24) [classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121] at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE] ... 18 common frames omitted
      

      Attachments

        Issue Links

          Activity

            People

              mp911de Mark Paluch
              snowdrop Snow Drop
              Spring Issues Spring Issues
              Votes:
              3 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: