You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2024/01/16 12:00:02 UTC

(causeway) branch 3674-NPE.paramsnapshot created (now b3342ad560)

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

ahuber pushed a change to branch 3674-NPE.paramsnapshot
in repository https://gitbox.apache.org/repos/asf/causeway.git


      at b3342ad560 CAUSEWAY-3674: allow param restore only if possible

This branch includes the following new commits:

     new b3342ad560 CAUSEWAY-3674: allow param restore only if possible

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(causeway) 01/01: CAUSEWAY-3674: allow param restore only if possible

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch 3674-NPE.paramsnapshot
in repository https://gitbox.apache.org/repos/asf/causeway.git

commit b3342ad5608fbef97a89db6356d49dd0872ab6ca
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Jan 16 12:59:56 2024 +0100

    CAUSEWAY-3674: allow param restore only if possible
---
 .../managed/PendingParamsSnapshot.java             | 29 ++++++++++++++++++++++
 .../interaction/act/ActionInteractionWkt.java      |  2 +-
 2 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/managed/PendingParamsSnapshot.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/managed/PendingParamsSnapshot.java
index 755ed4a8ab..efc0c3281d 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/managed/PendingParamsSnapshot.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/interactions/managed/PendingParamsSnapshot.java
@@ -23,6 +23,8 @@ import java.io.ObjectInputStream;
 import java.io.Serializable;
 import java.util.Objects;
 
+import org.springframework.lang.Nullable;
+
 import org.apache.causeway.applib.id.LogicalType;
 import org.apache.causeway.applib.services.bookmark.Bookmark;
 import org.apache.causeway.commons.collections.Can;
@@ -53,10 +55,18 @@ import lombok.NonNull;
 public class PendingParamsSnapshot implements Serializable {
     private static final long serialVersionUID = 1L;
 
+    // -- FACTORIES
+
     protected static PendingParamsSnapshot create(final ParameterNegotiationModel parameterNegotiationModel) {
         return new PendingParamsSnapshot(null, parameterNegotiationModel);
     }
 
+    private static PendingParamsSnapshot empty() {
+        return new PendingParamsSnapshot(null, null);
+    }
+
+    // -- CONSTRUCTION
+
     private Can<ManagedObject> parameterValues;
     private ParameterNegotiationModel parameterNegotiationModel;
 
@@ -64,6 +74,13 @@ public class PendingParamsSnapshot implements Serializable {
         return this.parameterNegotiationModel = ParameterNegotiationModel.of(managedAction, parameterValues);
     }
 
+    // -- UTILITY
+
+    public static boolean canRestore(final @Nullable PendingParamsSnapshot pendingParamsSnapshot) {
+        return pendingParamsSnapshot!=null
+                && pendingParamsSnapshot.parameterValues!=null;
+    }
+
     // -- SERIALIZATION PROXY
 
     private Object writeReplace() {
@@ -82,16 +99,28 @@ public class PendingParamsSnapshot implements Serializable {
          */
         private final LogicalType[] cardinalityConstraints;
         private final Can<Can<Bookmark>> argBookmarks;
+        private final boolean isEmpty;
 
         private SerializationProxy(final PendingParamsSnapshot pendingParamsSnapshot) {
+
+            // guard against ParameterNegotiationModel not available
+            if(pendingParamsSnapshot.parameterNegotiationModel==null) {
+                this.cardinalityConstraints = null;
+                this.argBookmarks = null;
+                this.isEmpty = true;
+                return;
+            }
+
             var objectManager = MetaModelContext.instanceElseFail().getObjectManager();
             this.cardinalityConstraints = new LogicalType[pendingParamsSnapshot.parameterNegotiationModel.getParamCount()];
             this.argBookmarks = pendingParamsSnapshot.parameterNegotiationModel
                 .getParamModels()
                 .map(paramModel->bookmark(objectManager, paramModel));
+            this.isEmpty = false;
         }
 
         private Object readResolve() {
+            if(isEmpty) return PendingParamsSnapshot.empty();
             var objectManager = MetaModelContext.instanceElseFail().getObjectManager();
             return new PendingParamsSnapshot(
                     argBookmarks
diff --git a/viewers/wicket/model/src/main/java/org/apache/causeway/viewer/wicket/model/models/interaction/act/ActionInteractionWkt.java b/viewers/wicket/model/src/main/java/org/apache/causeway/viewer/wicket/model/models/interaction/act/ActionInteractionWkt.java
index 202baa6159..98537e8aeb 100644
--- a/viewers/wicket/model/src/main/java/org/apache/causeway/viewer/wicket/model/models/interaction/act/ActionInteractionWkt.java
+++ b/viewers/wicket/model/src/main/java/org/apache/causeway/viewer/wicket/model/models/interaction/act/ActionInteractionWkt.java
@@ -221,7 +221,7 @@ extends HasBookmarkedOwnerAbstract<ActionInteraction> {
         }
 
         //[CAUSEWAY-3663] restore pending params, in case we do have a snapshot of these
-        if(pendingParamsSnapshot!=null) {
+        if(PendingParamsSnapshot.canRestore(pendingParamsSnapshot)) {
             this.parameterNegotiationModel =
                     pendingParamsSnapshot.restoreParameterNegotiationModel(
                             actionInteraction()