This is an automated email from the ASF dual-hosted git repository.
kenhuuu pushed a commit to branch 3.7-dev
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/3.7-dev by this push:
new ae1b2a88fc Strengthen nested strategy class configuration
ae1b2a88fc is described below
commit ae1b2a88fc7bee6ef5b8ac486dce9a10bb7d2660
Author: Ken Hu <[email protected]>
AuthorDate: Thu Aug 20 14:51:08 2026 -0700
Strengthen nested strategy class configuration
Assisted-by: Codex:gpt-5.6-sol
---
CHANGELOG.asciidoc | 1 +
.../strategy/decoration/VertexProgramStrategy.java | 13 ++-
.../decoration/HaltedTraverserStrategy.java | 26 ++---
.../finalization/MatchAlgorithmStrategy.java | 9 +-
.../decoration/VertexProgramStrategyTest.java | 124 +++++++++++++++++++++
.../decoration/HaltedTraverserStrategyTest.java | 58 ++++++++++
.../finalization/MatchAlgorithmStrategyTest.java | 83 ++++++++++++++
7 files changed, 297 insertions(+), 17 deletions(-)
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 55be83bfc1..5771275b27 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -37,6 +37,7 @@
image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
* Fixed `hasId()` to only unroll a collection when it is supplied as the
single argument, aligning its behavior with `g.V()`/`g.E()`.
* Allowed float literals without a leading digit (e.g. `.5`, `.5f`, `.5d`) in
the Gremlin grammar to better match Groovy.
* Fixed conjoin has incorrect null handling.
+* Strengthened nested class configuration for `HaltedTraverserStrategy`,
`MatchAlgorithmStrategy`, and `VertexProgramStrategy`.
* Bump Netty to 4.1.136.
* Bumped `jackson-databind` to 2.18.9. `InetAddress` values in GraphSON must
now be literal IP addresses as hostnames are no longer resolved during
deserialization. *(breaking)*
* Removed the Mono dependency from the `gremlin-dotnet` build/release process,
using `dotnet pack`/`dotnet nuget push` instead of `mono nuget.exe`.
diff --git
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
index fcd5a53c97..2b39b2c7ed 100644
---
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
+++
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
@@ -215,9 +215,16 @@ public final class VertexProgramStrategy extends
AbstractTraversalStrategy<Trave
try {
final VertexProgramStrategy.Builder builder =
VertexProgramStrategy.build();
for (final String key : (List<String>)
IteratorUtils.asList(configuration.getKeys())) {
- if (key.equals(GRAPH_COMPUTER))
- builder.graphComputer((Class)
Class.forName(configuration.getString(key)));
- else if (key.equals(WORKERS))
+ if (key.equals(GRAPH_COMPUTER)) {
+ final String graphComputer = configuration.getString(key);
+ // Provider graph computers are supported, so validate the
extension type before class initialization.
+ final Class<?> graphComputerClass =
Class.forName(graphComputer, false,
+ VertexProgramStrategy.class.getClassLoader());
+ if
(!GraphComputer.class.isAssignableFrom(graphComputerClass))
+ throw new IllegalArgumentException("The provided graph
computer is invalid: " + graphComputer);
+
+
builder.graphComputer(graphComputerClass.asSubclass(GraphComputer.class));
+ } else if (key.equals(WORKERS))
builder.workers(configuration.getInt(key));
else if (key.equals(PERSIST))
builder.persist(GraphComputer.Persist.valueOf(configuration.getString(key)));
diff --git
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
index cf2e8304f9..2cfada4988 100644
---
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
+++
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
@@ -39,12 +39,16 @@ public final class HaltedTraverserStrategy extends
AbstractTraversalStrategy<Tra
private final Class haltedTraverserFactory;
private final boolean useReference;
- private HaltedTraverserStrategy(final Class haltedTraverserFactory) {
- if (haltedTraverserFactory.equals(DetachedFactory.class) ||
haltedTraverserFactory.equals(ReferenceFactory.class)) {
- this.haltedTraverserFactory = haltedTraverserFactory;
- this.useReference =
ReferenceFactory.class.equals(this.haltedTraverserFactory);
- } else
- throw new IllegalArgumentException("The provided traverser
detachment factory is unknown: " + haltedTraverserFactory);
+ private HaltedTraverserStrategy(final String haltedTraverserFactory) {
+ if (DetachedFactory.class.getName().equals(haltedTraverserFactory))
+ this.haltedTraverserFactory = DetachedFactory.class;
+ else if
(ReferenceFactory.class.getName().equals(haltedTraverserFactory))
+ this.haltedTraverserFactory = ReferenceFactory.class;
+ else
+ throw new IllegalArgumentException("The provided traverser
detachment factory is unknown: " +
+ haltedTraverserFactory);
+
+ this.useReference =
ReferenceFactory.class.equals(this.haltedTraverserFactory);
}
public void apply(final Traversal.Admin<?, ?> traversal) {
@@ -66,11 +70,7 @@ public final class HaltedTraverserStrategy extends
AbstractTraversalStrategy<Tra
public static final String HALTED_TRAVERSER_FACTORY =
"haltedTraverserFactory";
public static HaltedTraverserStrategy create(final Configuration
configuration) {
- try {
- return new
HaltedTraverserStrategy(Class.forName(configuration.getString(HALTED_TRAVERSER_FACTORY)));
- } catch (final ClassNotFoundException e) {
- throw new IllegalArgumentException(e.getMessage(), e);
- }
+ return new
HaltedTraverserStrategy(configuration.getString(HALTED_TRAVERSER_FACTORY));
}
@Override
@@ -84,11 +84,11 @@ public final class HaltedTraverserStrategy extends
AbstractTraversalStrategy<Tra
////////////
public static HaltedTraverserStrategy detached() {
- return new HaltedTraverserStrategy(DetachedFactory.class);
+ return new HaltedTraverserStrategy(DetachedFactory.class.getName());
}
public static HaltedTraverserStrategy reference() {
- return new HaltedTraverserStrategy(ReferenceFactory.class);
+ return new HaltedTraverserStrategy(ReferenceFactory.class.getName());
}
}
diff --git
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/MatchAlgorithmStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/MatchAlgorithmStrategy.java
index 8f0d6c9f43..ab6d5fea12 100644
---
a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/MatchAlgorithmStrategy.java
+++
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/MatchAlgorithmStrategy.java
@@ -55,8 +55,15 @@ public final class MatchAlgorithmStrategy extends
AbstractTraversalStrategy<Trav
}
public static MatchAlgorithmStrategy create(final Configuration
configuration) {
+ final String matchAlgorithm = configuration.getString(MATCH_ALGORITHM);
try {
- return new MatchAlgorithmStrategy((Class)
Class.forName(configuration.getString(MATCH_ALGORITHM)));
+ // Provider algorithms are supported, so validate the extension
type before allowing class initialization.
+ final Class<?> matchAlgorithmClass = Class.forName(matchAlgorithm,
false,
+ MatchAlgorithmStrategy.class.getClassLoader());
+ if
(!MatchStep.MatchAlgorithm.class.isAssignableFrom(matchAlgorithmClass))
+ throw new IllegalArgumentException("The provided match
algorithm is invalid: " + matchAlgorithm);
+
+ return new
MatchAlgorithmStrategy(matchAlgorithmClass.asSubclass(MatchStep.MatchAlgorithm.class));
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
diff --git
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategyTest.java
new file mode 100644
index 0000000000..61500f8e2c
--- /dev/null
+++
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategyTest.java
@@ -0,0 +1,124 @@
+/*
+ * 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.tinkerpop.gremlin.process.computer.traversal.strategy.decoration;
+
+import org.apache.commons.configuration2.MapConfiguration;
+import org.apache.tinkerpop.gremlin.process.computer.ComputerResult;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.MapReduce;
+import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Property;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Future;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThrows;
+
+public class VertexProgramStrategyTest {
+
+ private static boolean providerGraphComputerInitialized = false;
+ private static boolean invalidGraphComputerInitialized = false;
+
+ @Test
+ public void shouldCreateStrategyForDefaultGraphComputer() {
+ create(GraphComputer.class.getName());
+ }
+
+ @Test
+ public void shouldCreateStrategyForProviderGraphComputer() {
+ create(ProviderGraphComputer.class.getName());
+
+ assertThat(providerGraphComputerInitialized, is(false));
+ }
+
+ @Test
+ public void shouldRejectInvalidGraphComputerWithoutInitializingIt() {
+ assertThrows(IllegalArgumentException.class, () ->
create(InvalidGraphComputer.class.getName()));
+ assertThat(invalidGraphComputerInitialized, is(false));
+ }
+
+ private static VertexProgramStrategy create(final String graphComputer) {
+ return VertexProgramStrategy.create(new MapConfiguration(
+ Collections.singletonMap(VertexProgramStrategy.GRAPH_COMPUTER,
graphComputer)));
+ }
+
+ public static final class ProviderGraphComputer implements GraphComputer {
+ static {
+ providerGraphComputerInitialized = true;
+ }
+
+ @Override
+ public GraphComputer result(final ResultGraph resultGraph) {
+ return this;
+ }
+
+ @Override
+ public GraphComputer persist(final Persist persist) {
+ return this;
+ }
+
+ @Override
+ public GraphComputer program(final VertexProgram vertexProgram) {
+ return this;
+ }
+
+ @Override
+ public GraphComputer mapReduce(final MapReduce mapReduce) {
+ return this;
+ }
+
+ @Override
+ public GraphComputer workers(final int workers) {
+ return this;
+ }
+
+ @Override
+ public GraphComputer vertices(final Traversal<Vertex, Vertex>
vertexFilter) {
+ return this;
+ }
+
+ @Override
+ public GraphComputer edges(final Traversal<Vertex, Edge> edgeFilter) {
+ return this;
+ }
+
+ @Override
+ public GraphComputer vertexProperties(final Traversal<Vertex, ?
extends Property<?>> vertexPropertyFilter) {
+ return this;
+ }
+
+ @Override
+ public Future<ComputerResult> submit() {
+ return new CompletableFuture<>();
+ }
+ }
+
+ private static final class InvalidGraphComputer {
+ static {
+ invalidGraphComputerInitialized = true;
+ }
+ }
+}
diff --git
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java
new file mode 100644
index 0000000000..f226e8772d
--- /dev/null
+++
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java
@@ -0,0 +1,58 @@
+/*
+ * 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.tinkerpop.gremlin.process.traversal.strategy.decoration;
+
+import org.apache.commons.configuration2.MapConfiguration;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedFactory;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThrows;
+
+public class HaltedTraverserStrategyTest {
+
+ private static boolean unapprovedFactoryInitialized = false;
+
+ @Test
+ public void shouldCreateStrategyForSupportedFactory() {
+
assertThat(create(DetachedFactory.class.getName()).getHaltedTraverserFactory(),
is(DetachedFactory.class));
+ }
+
+ @Test
+ public void shouldRejectUnsupportedFactoryWithoutLoadingIt() {
+ final String unapprovedFactory =
HaltedTraverserStrategyTest.class.getName() + "$UnapprovedFactory";
+
+ assertThrows(IllegalArgumentException.class, () ->
create(unapprovedFactory));
+ assertThat(unapprovedFactoryInitialized, is(false));
+ }
+
+ private static HaltedTraverserStrategy create(final String factory) {
+ return HaltedTraverserStrategy.create(new MapConfiguration(
+
Collections.singletonMap(HaltedTraverserStrategy.HALTED_TRAVERSER_FACTORY,
factory)));
+ }
+
+ private static final class UnapprovedFactory {
+ static {
+ unapprovedFactoryInitialized = true;
+ }
+ }
+}
diff --git
a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/MatchAlgorithmStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/MatchAlgorithmStrategyTest.java
new file mode 100644
index 0000000000..e935aaa970
--- /dev/null
+++
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/MatchAlgorithmStrategyTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.tinkerpop.gremlin.process.traversal.strategy.finalization;
+
+import org.apache.commons.configuration2.MapConfiguration;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
+import org.junit.Test;
+
+import java.util.Collections;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.junit.Assert.assertThrows;
+
+public class MatchAlgorithmStrategyTest {
+
+ private static boolean loadableProviderAlgorithmInitialized = false;
+ private static boolean invalidAlgorithmInitialized = false;
+
+ @Test
+ public void shouldCreateStrategyForDefaultMatchAlgorithm() {
+ final String defaultAlgorithm =
MatchStep.CountMatchAlgorithm.class.getName();
+ final MatchAlgorithmStrategy strategy = create(defaultAlgorithm);
+
+ assertThat(strategy.getConfiguration().getString("matchAlgorithm"),
is(defaultAlgorithm));
+ }
+
+ @Test
+ public void shouldLoadValidProviderMatchAlgorithm() {
+ final String providerAlgorithm =
LoadableProviderMatchAlgorithm.class.getName();
+ final Traversal.Admin<?, ?> traversal =
__.match(__.as("a").out().as("b")).asAdmin();
+
+ create(providerAlgorithm).apply(traversal);
+ final MatchStep<?, ?> matchStep = (MatchStep<?, ?>)
traversal.getStartStep();
+
+ assertThat(matchStep.getMatchAlgorithm(),
instanceOf(LoadableProviderMatchAlgorithm.class));
+ assertThat(loadableProviderAlgorithmInitialized, is(true));
+ }
+
+ @Test
+ public void shouldRejectInvalidMatchAlgorithmWithoutInitializingIt() {
+ final String invalidAlgorithm = InvalidAlgorithm.class.getName();
+
+ assertThrows(IllegalArgumentException.class, () ->
create(invalidAlgorithm));
+ assertThat(invalidAlgorithmInitialized, is(false));
+ }
+
+ private static MatchAlgorithmStrategy create(final String matchAlgorithm) {
+ return MatchAlgorithmStrategy.create(new MapConfiguration(
+ Collections.singletonMap("matchAlgorithm", matchAlgorithm)));
+ }
+
+ public static final class LoadableProviderMatchAlgorithm extends
MatchStep.CountMatchAlgorithm {
+ static {
+ loadableProviderAlgorithmInitialized = true;
+ }
+ }
+
+ private static final class InvalidAlgorithm {
+ static {
+ invalidAlgorithmInitialized = true;
+ }
+ }
+}