This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch CAUSEWAY-3688
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit 32311afee36b7e8f9f204f7ef621ec96df301876
Author: danhaywood <[email protected]>
AuthorDate: Wed Feb 21 13:52:02 2024 +0000

    CAUSEWAY-3688: adds guard if fail to read pre value when deleting
---
 .../services/objectlifecycle/PropertyChangeRecord.java  | 16 ++++++++++++++--
 .../objectlifecycle/PropertyValuePlaceholder.java       | 17 +++++++++++++++++
 2 files changed, 31 insertions(+), 2 deletions(-)

diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java
index d233612b2a..df90b09f2e 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyChangeRecord.java
@@ -69,8 +69,8 @@ public final class PropertyChangeRecord {
     public static PropertyChangeRecord ofDeleting(
             final @NonNull PropertyChangeRecordId id) {
         return new PropertyChangeRecord(id)
-                        .withPreValueSetToCurrent()
-                        .withPostValueSetToDeleted();
+                .withPreValueSetToCurrentElseUnknown()
+                .withPostValueSetToDeleted();
     }
 
     private PropertyChangeRecord(final @NonNull PropertyChangeRecordId id) {
@@ -91,6 +91,18 @@ public final class PropertyChangeRecord {
         return withPreValueSetTo(getPropertyValue());
     }
 
+    private PropertyChangeRecord withPreValueSetToCurrentElseUnknown() {
+        try {
+            return withPreValueSetToCurrent();
+        } catch (Exception ex) {
+            return withPreValueSetToUnknown();
+        }
+    }
+
+    private PropertyChangeRecord withPreValueSetToUnknown() {
+        return withPreValueSetTo(PropertyValuePlaceholder.UNKNOWN);
+    }
+
     public PropertyChangeRecord withPostValueSetToCurrent() {
         return withPostValueSetTo(getPropertyValue());
     }
diff --git 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyValuePlaceholder.java
 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyValuePlaceholder.java
index 02910506fb..dbc9758f9c 100644
--- 
a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyValuePlaceholder.java
+++ 
b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/services/objectlifecycle/PropertyValuePlaceholder.java
@@ -25,8 +25,25 @@ package 
org.apache.causeway.core.metamodel.services.objectlifecycle;
  */
 public enum PropertyValuePlaceholder {
 
+    /**
+     * Indicates that the audit trail was unable to determine the value of the 
property, possibly because an
+     * exception was thrown.
+     *
+     * <p>
+     *     One way this can happen is if the property is derived but its 
implementation does not guard against
+     *     null references to other related objects.  In particular, this 
could occur when deleting an aggregate root
+     *     that surfaces the properties of its child entity items directly.  
The child entity is deleted first, and
+     *     then the aggregate root, but attempting to capture the value of 
this derived property the fails.
+     * </p>
+     */
     UNKNOWN,
+    /**
+     * Used as the <i>pre</i> value of a property for an object that is being 
created.
+     */
     NEW,
+    /**
+     * Used as the <i>post</i> value of a property for an object that has been 
deleted.
+     */
     DELETED
     ;
 

Reply via email to