Uploaded image for project: 'Spring Data Commons'
  1. Spring Data Commons
  2. DATACMNS-1461

Auditor attempts to set created date on null object

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.2 M1 (Moore), 2.1.3 (Lovelace SR3)
    • Component/s: None
    • Labels:
      None

      Description

      I have two classes, ClassB contains `@CreatedDate` property and is referenced by ClassA

      @Document(collection = "ClassA")
      public class ClassA {
      
          @Id
          private String id;
      
          private ClassB other;
      }
      
      public class ClassB {
      
          @CreatedDate
          private Instant created;
      }
      

      If I try to store instance of ClassA when `other` is null, the auditor fails with following exception:

      classARepository.save(new ClassA());
      
      org.springframework.data.mapping.MappingException: Cannot lookup property private ClassB ClassA.other on null intermediate! Original path was: other.created on ClassA.
      
      	at org.springframework.data.mapping.PersistentPropertyAccessor.setProperty(PersistentPropertyAccessor.java:70)
      	at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.lambda$setDateProperty$2(MappingAuditableBeanWrapperFactory.java:243)
      	at java.lang.Iterable.forEach(Iterable.java:75)
      	at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setDateProperty(MappingAuditableBeanWrapperFactory.java:243)
      	at org.springframework.data.auditing.MappingAuditableBeanWrapperFactory$MappingMetadataAuditableBeanWrapper.setCreatedDate(MappingAuditableBeanWrapperFactory.java:189)
      	at org.springframework.data.auditing.AuditingHandler.lambda$touchDate$9(AuditingHandler.java:219)
      	at java.util.Optional.ifPresent(Optional.java:159)
      	at org.springframework.data.auditing.AuditingHandler.touchDate(AuditingHandler.java:219)
      	at org.springframework.data.auditing.AuditingHandler.lambda$touch$0(AuditingHandler.java:166)
      	at java.util.Optional.map(Optional.java:215)
      	at org.springframework.data.auditing.AuditingHandler.touch(AuditingHandler.java:163)
      	at org.springframework.data.auditing.AuditingHandler.markCreated(AuditingHandler.java:131)
      	at org.springframework.data.auditing.IsNewAwareAuditingHandler.markAudited(IsNewAwareAuditingHandler.java:83)
      	at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.lambda$onApplicationEvent$0(AuditingEventListener.java:54)
      	at org.springframework.data.mongodb.core.mapping.event.MongoMappingEvent.mapSource(MongoMappingEvent.java:90)
      	at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.onApplicationEvent(AuditingEventListener.java:54)
      	at org.springframework.data.mongodb.core.mapping.event.AuditingEventListener.onApplicationEvent(AuditingEventListener.java:32)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
      	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:398)
      	at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:355)
      	at org.springframework.data.mongodb.core.MongoTemplate.maybeEmitEvent(MongoTemplate.java:2251)
      	at org.springframework.data.mongodb.core.MongoTemplate.doInsert(MongoTemplate.java:1216)
      	at org.springframework.data.mongodb.core.MongoTemplate.insert(MongoTemplate.java:1159)
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              olivergierke Oliver Drotbohm
              Reporter:
              dart0 Lukas Krecan
              Last updater:
              Oliver Drotbohm
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: