From 2334e6cf82365ec08de0a1645863205ca4f942dc Mon Sep 17 00:00:00 2001 From: opencode Date: Wed, 29 Jul 2026 11:50:40 +0000 Subject: [PATCH 1/4] [MPH-191] Fix help:evaluate failing on Java 18+ due to Hashtable reflection Change PropertiesConverter.canConvert() to use isAssignableFrom() instead of exact class match, so that subclasses of Properties (e.g. SortedProperties) are handled without falling through to SerializableConverter which tries to reflectively access java.util.Hashtable.table, forbidden on Java 18+. --- src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java index 4121208a..f8508356 100644 --- a/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EvaluateMojo.java @@ -385,7 +385,7 @@ private XStream getXStream() { /** {@inheritDoc} */ @Override public boolean canConvert(Class type) { - return Properties.class == type; + return Properties.class.isAssignableFrom(type); } /** {@inheritDoc} */ From b6de1c710b035275d1f1dbd19efce15357e4349d Mon Sep 17 00:00:00 2001 From: opencode Date: Wed, 29 Jul 2026 11:54:58 +0000 Subject: [PATCH 2/4] Add test for Properties subclass serialization in help:evaluate --- .../maven/plugins/help/EvaluateMojoTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java index 5fe15de0..994ff260 100644 --- a/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/help/EvaluateMojoTest.java @@ -20,6 +20,7 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; +import java.util.Properties; import org.apache.maven.api.di.Provides; import org.apache.maven.api.plugin.testing.InjectMojo; @@ -37,6 +38,7 @@ import static org.apache.maven.api.plugin.testing.MojoExtension.setVariableValueToObject; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; @@ -184,4 +186,45 @@ void testEvaluateQuiteModeWithOutputOnStdout(EvaluateMojo mojo) throws Exception assertEquals("org.apache.maven.its.help", stdResult); verify(log, never()).warn(anyString()); } + + /** + * Tests that a {@code Properties} subclass (like {@code SortedProperties}) is correctly serialized + * by XStream without falling through to {@code SerializableConverter} which would attempt + * reflective access to {@code java.util.Hashtable.table} (forbidden on Java 18+). + * @throws Exception in case of errors. + */ + @Test + @ResourceLock(Resources.SYSTEM_OUT) + @InjectMojo(goal = "evaluate") + @MojoParameter(name = "forceStdout", value = "true") + @MojoParameter(name = "expression", value = "project.properties") + void testEvaluateWithPropertiesSubclass(EvaluateMojo mojo) throws Exception { + Properties sortedProperties = new AbstractEffectiveMojo.SortedProperties(); + sortedProperties.setProperty("key1", "value1"); + sortedProperties.setProperty("key2", "value2"); + + when(expressionEvaluator.evaluate(anyString())).thenReturn(sortedProperties); + when(log.isInfoEnabled()).thenReturn(false); + + setVariableValueToObject(mojo, "evaluator", expressionEvaluator); + + PrintStream saveOut = System.out; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos)); + + try { + mojo.execute(); + } finally { + System.setOut(saveOut); + baos.close(); + } + + String stdResult = baos.toString(); + // Verify serialization succeeded without falling through to SerializableConverter + assertTrue(stdResult.contains("key1")); + assertTrue(stdResult.contains("value1")); + assertTrue(stdResult.contains("key2")); + assertTrue(stdResult.contains("value2")); + verify(log, never()).warn(anyString()); + } } From 1df5403965f9bdec8474ad91d1db06d99db7a765 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Tue, 4 Aug 2026 12:48:44 +0000 Subject: [PATCH 3/4] Fix #406: make evaluate-artifact-with-expression-with-output IT hermetic --- .../evaluate-artifact-with-expression-with-output/pom.xml | 3 +++ .../test.properties | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml b/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml index 9ee377e0..5f0d37c2 100644 --- a/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml +++ b/src/it/projects/evaluate-artifact-with-expression-with-output/pom.xml @@ -41,6 +41,9 @@ under the License. evaluate package + + org.apache.maven.plugins:maven-help-plugin:@project.version@ + diff --git a/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties b/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties index 632b331f..5f9820fd 100644 --- a/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties +++ b/src/it/projects/evaluate-artifact-with-expression-with-output/test.properties @@ -17,4 +17,3 @@ expression = project.name output = result.txt -artifact = org.apache.maven.plugins:maven-help-plugin From c5a2391375c8f287060432be5481f4c5e139f4f3 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Tue, 4 Aug 2026 13:02:03 +0000 Subject: [PATCH 4/4] Fix #406: make effective-pom-artifact ITs hermetic too --- src/it/projects/effective-pom-artifact/pom.xml | 12 ++++++++++++ .../projects/effective-pom-artifact/test.properties | 1 - .../effective-pom-multimodule-artifact/pom.xml | 8 ++++++++ .../test.properties | 1 - 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/it/projects/effective-pom-artifact/pom.xml b/src/it/projects/effective-pom-artifact/pom.xml index 8fc07074..95652047 100644 --- a/src/it/projects/effective-pom-artifact/pom.xml +++ b/src/it/projects/effective-pom-artifact/pom.xml @@ -27,4 +27,16 @@ under the License. 1.0-SNAPSHOT https://issues.apache.org/jira/browse/MPH-106 + + + + org.apache.maven.plugins + maven-help-plugin + @project.version@ + + org.apache.maven.plugins:maven-help-plugin:@project.version@ + + + + diff --git a/src/it/projects/effective-pom-artifact/test.properties b/src/it/projects/effective-pom-artifact/test.properties index 037f045e..ba5a1eec 100644 --- a/src/it/projects/effective-pom-artifact/test.properties +++ b/src/it/projects/effective-pom-artifact/test.properties @@ -16,4 +16,3 @@ # under the License. output = result.txt -artifact = org.apache.maven.plugins:maven-help-plugin diff --git a/src/it/projects/effective-pom-multimodule-artifact/pom.xml b/src/it/projects/effective-pom-multimodule-artifact/pom.xml index bf048a59..0daeb985 100644 --- a/src/it/projects/effective-pom-multimodule-artifact/pom.xml +++ b/src/it/projects/effective-pom-multimodule-artifact/pom.xml @@ -36,6 +36,14 @@ under the License. + + org.apache.maven.plugins + maven-help-plugin + @project.version@ + + org.apache.maven.plugins:maven-help-plugin:@project.version@ + + diff --git a/src/it/projects/effective-pom-multimodule-artifact/test.properties b/src/it/projects/effective-pom-multimodule-artifact/test.properties index 037f045e..ba5a1eec 100644 --- a/src/it/projects/effective-pom-multimodule-artifact/test.properties +++ b/src/it/projects/effective-pom-multimodule-artifact/test.properties @@ -16,4 +16,3 @@ # under the License. output = result.txt -artifact = org.apache.maven.plugins:maven-help-plugin