xh123637 opened a new pull request, #14011:
URL: https://github.com/apache/maven/pull/14011

   <!--
   Please open pull requests against one of the following branches:
   
   - master — default target for all changes (new features + bug fixes).  
     If the change should also go to maven-4.0.x, request a backport in the PR.
   
   - maven-3.10.x — target for 3.x changes (new features + bug fixes).  
     If the change should also go to maven-3.9.x, request a backport in the PR.
     maven-3.9.x should receive only serious bug fixes, as it is approaching 
EOL.
   
   Backports are typically handled by maintainers; 
   however, after agreement you may open a separate backport PR to the target 
maintenance branch.
   -->
   
   Fixes #14007.
   
   `V4MojoConfigurator.convert()` evaluated every leaf configuration node with 
`evaluateNodeAsString()` and then re-instantiated the parameter type with its 
no-arg constructor. When the node's expression evaluates to an object that is 
already an instance of the parameter type — for example 
`${project.mainArtifact}` for a `ProducedArtifact` parameter — the evaluated 
object was discarded, and `instantiate()` failed with `NoSuchMethodException` 
because the type has no no-arg constructor. This broke the released 
maven-compiler-plugin 4.0.0-beta-5 on master.
   
   The fix: in `convert()`, for a leaf node (no children), evaluate the node 
without coercion after `resolveImplementation()`, and if the result is an 
instance of the (possibly implementation-resolved) parameter type, assign it 
directly. Plain text values are not instances of the parameter type, so they 
fall through to the existing string conversion, default-setter, record, and 
bean paths unchanged. The `default-value` attribute path is covered as well, 
since `evaluateNode()` already falls back to it.
   
   Tests added in `V4MojoConfiguratorTest`:
   - `testExpressionEvaluatingToParameterTypeInstanceIsAssignedDirectly`
   - 
`testExpressionEvaluatingToParameterTypeInstanceViaDefaultValueIsAssignedDirectly`
   
   Both new tests fail on the unmodified code (the configurator throws 
`PluginConfigurationException` caused by `NoSuchMethodException`) and pass with 
the fix.
   
   What was run: the full `V4MojoConfiguratorTest` class (18 tests, including 
the 2 new ones) was compiled with `javac` and run with the JUnit Platform 
console against the HEAD sources of `V4MojoConfigurator`, 
`XmlNode`/`XmlNodeImpl`, and minimal stubs for the untouched 
`PluginDescriptor`/`PluginConfigurationException`/Plexus evaluator types: 18/18 
passed. A standalone harness with a fake evaluator returning an object instance 
for `${project.mainArtifact}` also confirmed the exact reported failure before 
the fix and the direct assignment after it, with String, structured-bean, and 
default-setter cases unchanged.
   
   What was not run: the full Maven build (`mvn -pl impl/maven-core verify` / 
`mvn -Prun-its verify`) could not be run in this environment (no Maven 
installation and no access to the full reactor build), so CI is the arbiter for 
the module and integration suites. `mvn spotless:apply` could not be run 
either; the change follows the surrounding code style.
   
   CI status: CI running, recheck pending.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [ ] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to