You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by da...@apache.org on 2026/06/25 22:18:39 UTC
(causeway) 03/05: CAUSEWAY-4039: adds POST_PROCESS navigation-action synthesis strategy
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch CAUSEWAY-4039
in repository https://gitbox.apache.org/repos/asf/causeway.git
commit 35f5145e3341706cc643047c265ecbe4df3c2c6e
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jun 25 23:21:06 2026 +0200
CAUSEWAY-4039: adds POST_PROCESS navigation-action synthesis strategy
Introduces a configurable strategy for synthesising the synthetic navigation
("selector") actions for parented collections / scalar references, selected via
causeway.extensions.command-log.navigation-action-synthesis = INLINE | POST_PROCESS
INLINE (default): the original behaviour, preserved. Own collections are
synthesised eagerly during introspection (ObjectSpecificationDefault) and
mixed-in collections lazily via ensureNavigationActionsForMixedInAssociations()
(now re-entrancy-guarded by the navigationActionAdder one-shot).
POST_PROCESS: a dedicated MetaModelPostProcessor
(SynthesizeNavigationActionsPostProcessor, registered A0_BEFORE_BUILTIN so the
synthesised actions still receive downstream facet post-processing) synthesises
both own and mixed-in navigation actions once per type. This keeps synthesis out
of the lazy streamDeclaredActions path, so it no longer forces re-entrant
element-type introspection during ordinary action access — the root cause of the
StackOverflow on cyclic collection graphs.
- ObjectSpecificationAbstract: extract shared addNavigationActions(Stream); gate
inline path behind !isNavigationActionPostProcessing(); add public
synthesizeNavigationActions() entry point for the post-processor.
- ObjectSpecificationDefault: read strategy from config; skip eager synthesis in
POST_PROCESS mode; override isNavigationActionPostProcessing().
Default is unchanged (INLINE); existing navigation/recording tests pass.
Co-Authored-By: Claude Opus 4.8 (1M context) <no...@anthropic.com>
---
.../core/config/CausewayConfiguration.java | 38 ++++++++++++
.../SynthesizeNavigationActionsPostProcessor.java | 67 ++++++++++++++++++++++
.../dflt/ProgrammingModelFacetsJava11.java | 6 ++
.../specimpl/ObjectSpecificationAbstract.java | 41 ++++++++++---
.../specimpl/dflt/ObjectSpecificationDefault.java | 13 ++++-
5 files changed, 157 insertions(+), 8 deletions(-)
diff --git a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
index 1e068123f4e..41416a85d7c 100644
--- a/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
+++ b/core/config/src/main/java/org/apache/causeway/core/config/CausewayConfiguration.java
@@ -4011,6 +4011,44 @@ public boolean isEnabled() {
}
}
+ /**
+ * How the synthetic navigation ("selector") actions for parented collections and scalar references
+ * are synthesized into the metamodel, when {@link #getRecordingSupport() recording-support} is enabled.
+ *
+ * <p>
+ * External property: {@code causeway.extensions.command-log.navigation-action-synthesis}.
+ * Accepted values are {@code INLINE} and {@code POST_PROCESS}.
+ * </p>
+ */
+ private NavigationActionSynthesis navigationActionSynthesis = NavigationActionSynthesis.INLINE;
+
+ public enum NavigationActionSynthesis {
+ /**
+ * Synthesize navigation actions inline during introspection: eagerly for a type's own
+ * parented collections, and lazily (on first access) for those contributed by mixins.
+ *
+ * <p>
+ * This is the original strategy. It is guarded against re-entrancy, but still forces full
+ * introspection of collection element types from the lazy action-streaming path, so a cyclic
+ * collection graph results in deep (if now bounded) recursion during metamodel loading.
+ * </p>
+ */
+ INLINE,
+ /**
+ * Synthesize navigation actions in a dedicated metamodel post-processor, once per type,
+ * covering both own and mixed-in parented collections.
+ *
+ * <p>
+ * This keeps navigation-action synthesis out of the lazy {@code streamDeclaredActions} path,
+ * so it no longer forces re-entrant element-type introspection during ordinary action access.
+ * </p>
+ */
+ POST_PROCESS;
+
+ public boolean isInline() { return this == INLINE; }
+ public boolean isPostProcess() { return this == POST_PROCESS; }
+ }
+
private final ReplayResultMapping replayResultMapping = new ReplayResultMapping();
@Data
public static class ReplayResultMapping {
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/members/navigation/SynthesizeNavigationActionsPostProcessor.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/members/navigation/SynthesizeNavigationActionsPostProcessor.java
new file mode 100644
index 00000000000..c142db9f9dc
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/postprocessors/members/navigation/SynthesizeNavigationActionsPostProcessor.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.causeway.core.metamodel.postprocessors.members.navigation;
+
+import javax.inject.Inject;
+
+import org.apache.causeway.core.config.CausewayConfiguration.Extensions.CommandLog;
+import org.apache.causeway.core.metamodel.context.MetaModelContext;
+import org.apache.causeway.core.metamodel.postprocessors.MetaModelPostProcessorAbstract;
+import org.apache.causeway.core.metamodel.spec.ObjectSpecification;
+import org.apache.causeway.core.metamodel.specloader.specimpl.ObjectSpecificationAbstract;
+
+/**
+ * Synthesizes the synthetic navigation ("selector") actions for parented collections (and scalar
+ * references) once per type, during the post-processing phase.
+ *
+ * <p>
+ * Active only when command-log recording support is enabled <i>and</i> the
+ * {@link CommandLog.NavigationActionSynthesis#POST_PROCESS POST_PROCESS} synthesis strategy is selected
+ * (see {@code causeway.extensions.command-log.navigation-action-synthesis}). Under the default inline
+ * strategy this post-processor is disabled and synthesis happens during introspection instead.
+ *
+ * <p>
+ * Performing synthesis here (rather than from the lazy {@code streamDeclaredActions} path) keeps it out of
+ * ordinary action access, so it no longer forces re-entrant introspection of collection element types and
+ * cannot recurse without bound on a cyclic collection graph.
+ */
+public class SynthesizeNavigationActionsPostProcessor
+extends MetaModelPostProcessorAbstract {
+
+ @Inject
+ public SynthesizeNavigationActionsPostProcessor(final MetaModelContext mmc) {
+ super(mmc);
+ }
+
+ @Override
+ public boolean isEnabled() {
+ final CommandLog commandLog = getMetaModelContext().getConfiguration()
+ .getExtensions().getCommandLog();
+ return commandLog.getRecordingSupport().isEnabled()
+ && commandLog.getNavigationActionSynthesis().isPostProcess();
+ }
+
+ @Override
+ public void postProcessObject(final ObjectSpecification objSpec) {
+ if (objSpec instanceof ObjectSpecificationAbstract) {
+ ((ObjectSpecificationAbstract) objSpec).synthesizeNavigationActions();
+ }
+ }
+
+}
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java
index e3d00066e61..c125ad3b2cc 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/progmodels/dflt/ProgrammingModelFacetsJava11.java
@@ -94,6 +94,7 @@
import org.apache.causeway.core.metamodel.postprocessors.allbutparam.authorization.AuthorizationPostProcessor;
import org.apache.causeway.core.metamodel.postprocessors.members.SynthesizeDomainEventsForMixinPostProcessor;
import org.apache.causeway.core.metamodel.postprocessors.members.navigation.NavigationFacetFromHiddenTypePostProcessor;
+import org.apache.causeway.core.metamodel.postprocessors.members.navigation.SynthesizeNavigationActionsPostProcessor;
import org.apache.causeway.core.metamodel.postprocessors.object.ProjectionFacetsPostProcessor;
import org.apache.causeway.core.metamodel.postprocessors.param.ChoicesAndDefaultsPostProcessor;
import org.apache.causeway.core.metamodel.postprocessors.param.TypicalLengthFromTypePostProcessor;
@@ -251,6 +252,11 @@ private void addPostProcessors() {
val mmc = getMetaModelContext();
+ // synthesize navigation ("selector") actions before the builtin post-processors run, so that the
+ // synthesized actions still receive described-as / typical-length / authorization / etc post-processing.
+ // No-op unless command-log recording support is enabled with the POST_PROCESS synthesis strategy.
+ addPostProcessor(PostProcessingOrder.A0_BEFORE_BUILTIN, new SynthesizeNavigationActionsPostProcessor(mmc));
+
// must run before Object nouns are used
addPostProcessor(PostProcessingOrder.A1_BUILTIN, new SynthesizeObjectNamingPostProcessor(mmc));
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java
index 3b8020aad8b..2ad082f7519 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/ObjectSpecificationAbstract.java
@@ -997,7 +997,9 @@ private void createMixedInAssociationsAndResort() {
* without treating ordinary mixin actions as navigation sources.
*/
private void ensureNavigationActionsForMixedInAssociations() {
- if (!isRecordingSupportEnabled()) {
+ if (!isRecordingSupportEnabled()
+ || isNavigationActionPostProcessing()) {
+ // in POST_PROCESS mode, synthesis is performed once by SynthesizeNavigationActionsPostProcessor
return;
}
// one-shot: synthesize navigation actions at most once per spec.
@@ -1006,29 +1008,46 @@ private void ensureNavigationActionsForMixedInAssociations() {
// childSpec.streamAssociations), whose own post-processing re-enters this method.
// With a cyclic collection graph (A.coll<B>, B.coll<A>, parent/child trees, ...) that
// would otherwise recurse forever and blow the stack.
- navigationActionAdder.trigger(this::doEnsureNavigationActionsForMixedInAssociations);
+ navigationActionAdder.trigger(() -> addNavigationActions(
+ stream(unmodifiableAssociations.get())
+ .filter(MixedInMember.class::isInstance)));
}
- private void doEnsureNavigationActionsForMixedInAssociations() {
+ /**
+ * Synthesizes navigation actions for <i>all</i> parented collections (own and mixed-in), once per spec.
+ * <p>
+ * Invoked by {@code SynthesizeNavigationActionsPostProcessor} when the
+ * {@code POST_PROCESS} navigation-action-synthesis strategy is selected; a no-op under the
+ * (default) inline strategy, which synthesizes actions during introspection instead.
+ */
+ public void synthesizeNavigationActions() {
+ if (!isRecordingSupportEnabled()
+ || !isNavigationActionPostProcessing()) {
+ return;
+ }
+ navigationActionAdder.trigger(() -> addNavigationActions(
+ streamAssociations(MixedIn.INCLUDED)));
+ }
+
+ private void addNavigationActions(final Stream<ObjectAssociation> candidateAssociations) {
mixedInAssociationAdder.trigger(this::createMixedInAssociationsAndResort);
val existingActionIds = objectActions.stream()
.map(ObjectAction::getId)
.collect(Collectors.toSet());
- val mixedInAssociationsWithoutNavigation = stream(unmodifiableAssociations.get())
- .filter(MixedInMember.class::isInstance)
+ val associationsWithoutNavigation = candidateAssociations
.filter(association -> !existingActionIds.contains(
ParentedCollectionNavigationActionUtil.ACTION_ID_PREFIX + association.getId()))
.collect(Can.toCan());
val parentedCollectionNavigationActions = ParentedCollectionNavigationActionUtil
- .createFor(this, mixedInAssociationsWithoutNavigation.stream())
+ .createFor(this, associationsWithoutNavigation.stream())
.collect(Can.toCan());
existingActionIds.addAll(parentedCollectionNavigationActions.stream()
.map(ObjectAction::getId)
.collect(Collectors.toSet()));
val navigationActions = Stream.concat(
parentedCollectionNavigationActions.stream(),
- ScalarReferenceNavigationActionUtil.createFor(this, mixedInAssociationsWithoutNavigation.stream(), existingActionIds))
+ ScalarReferenceNavigationActionUtil.createFor(this, associationsWithoutNavigation.stream(), existingActionIds))
.collect(Collectors.toList());
if (navigationActions.isEmpty()) {
return;
@@ -1044,6 +1063,14 @@ protected boolean isRecordingSupportEnabled() {
return false;
}
+ /**
+ * Whether navigation-action synthesis is deferred to the post-processing phase (the {@code POST_PROCESS}
+ * strategy) rather than performed inline during introspection. Defaults to {@code false} (inline).
+ */
+ protected boolean isNavigationActionPostProcessing() {
+ return false;
+ }
+
@Getter(lazy = true)
private final CausewayBeanTypeRegistry causewayBeanTypeRegistry =
getServiceRegistry()
diff --git a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/dflt/ObjectSpecificationDefault.java b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/dflt/ObjectSpecificationDefault.java
index 76c0e14284f..07ec4791768 100644
--- a/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/dflt/ObjectSpecificationDefault.java
+++ b/core/metamodel/src/main/java/org/apache/causeway/core/metamodel/specloader/specimpl/dflt/ObjectSpecificationDefault.java
@@ -87,6 +87,7 @@ public class ObjectSpecificationDefault
private final ClassSubstitutorRegistry classSubstitutorRegistry;
private final _MembersAsColumns columnHelper;
private final boolean recordingSupportEnabled;
+ private final boolean navigationActionPostProcessing;
@Getter(onMethod_ = {@Override})
private final IntrospectionPolicy introspectionPolicy;
@@ -124,6 +125,8 @@ public ObjectSpecificationDefault(
this.columnHelper = new _MembersAsColumns(mmc);
this.recordingSupportEnabled = mmc.getConfiguration().getExtensions().getCommandLog()
.getRecordingSupport().isEnabled();
+ this.navigationActionPostProcessing = mmc.getConfiguration().getExtensions().getCommandLog()
+ .getNavigationActionSynthesis().isPostProcess();
}
@Override
@@ -188,7 +191,10 @@ protected void introspectMembers() {
val associations = createAssociations().collect(Can.toCan());
replaceAssociations(associations.stream());
val actions = createActions().collect(Can.toCan());
- if (recordingSupportEnabled) {
+ if (recordingSupportEnabled && !navigationActionPostProcessing) {
+ // inline strategy: synthesize navigation actions for own collections eagerly here;
+ // mixed-in collections are handled lazily by ensureNavigationActionsForMixedInAssociations().
+ // (POST_PROCESS strategy defers all synthesis to SynthesizeNavigationActionsPostProcessor.)
val parentedCollectionNavigationActions = ParentedCollectionNavigationActionUtil
.createFor(this, associations.stream())
.collect(Can.toCan());
@@ -212,6 +218,11 @@ protected boolean isRecordingSupportEnabled() {
return recordingSupportEnabled;
}
+ @Override
+ protected boolean isNavigationActionPostProcessing() {
+ return navigationActionPostProcessing;
+ }
+
private void addNamedFacetIfRequired() {
if (getFacet(MemberNamedFacet.class) == null) {
addFacet(new MemberNamedFacetForStaticMemberName(