apache / apache/maven

[MNG-7610] ValidatingConfigurationListener doesn't validate, causing wrong "parameters ... are missing or invalid" errors

Open
#8,842 2 comments 0 reactions 1 assignee Claimed by @slawekjaranowski View on GitHub
bug priority:major
Dominant language
Java
Stars
5.3k
Forks
3.1k
Avg merge
20h 42m
Merged PRs (30d)
297

Description

**[Peter Bugla](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=JIRAUSER298444)** opened **[MNG-7610](https://issues.apache.org/jira/browse/MNG-7610?redirect=false)** and commented

Applies to mvn 3.8.6 (and at least some earlier versions, but our project uses 3.8.6 now), mvn-core.

{**}Short description{**}:

ValidatingConfigurationListener (see constructor) considers all parameters marked as required in a plugin as missing, causing an otherwise perfectly fine mvn run to wrongly end with an error statement

Detailed description:

**Short intro** / history / pointing out that it's not my rare irrelevant personal issue:
There are already some articles on StackOverflow getting the following error message after an mvn run that uses a plugin, which has at least one required parameter.
Apart from obvious user errors, where someone just forgot to set a required parameter, looking closely there are also a bunch of cases (including mine) where the required parameter(s) are set perfectly fine, the triggered plugin execution used them successfully, so they were obviously there, but mvn still ends with the error statement.:

[ERROR] Failed to execute goal :::\ (default-cli) on project : The parameters '' for goal :::\ are missing or invalid

---

**Specific example** (the one I encountered):
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project qat.lup.alltests: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java are missing or invalid

Excerpt from my pom.xml:
            \
                \org.codehaus.mojo\
                \exec-maven-plugin\
                \3.1.0\
                \
                    \
                        \MyExecutionId\
                        \
                            \java\
                        \
                    \
                \
                \
                    \full.package.ClassName\
                    \
                        \argument_1_for_class_ClassName\
                        \argument_2_for_class_ClassName\
                        \argument_3_for_class_ClassName\
                    \
                \
            \

Started with:
mvn -s settings.xml exec:java

Run result:
The execution of full.package.ClassName via the plugin worked perfectly. So obviously "mainClass" was found and read correctly by exec-maven-plugin, otherwise it would have failed.
However that mvn run always ends with the error message:
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java (default-cli) on project qat.lup.alltests: The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:3.1.0:java are missing or invalid

---

**My analysis** (all file names and line numbers are references against mvn 3.8.6 checked out with the according tag from your git):
As there was no answer in StackOverflow that worked for me, I dug deeper in my case:
The relevant configuration in plugin.xml of org.codehaus.mojo:exec-maven-plugin:3.1.0 concerning the parameter mainClass seems fine (it's set as required as expected, no visible issue with that).

So I checked where that error message originates from and backtrack from there:
- The error message is from
  PluginParameterException.java:45 (org.apache.maven.plugin.PluginParameterException) (in constructor).
- this (in the relevant case) is called from DefaultMavenPluginManager.java (in multiple places, but I believe the relevant one here is:
  DefaultMavenPluginManager.java:644 (org.apache.maven.plugin.internal.DefaultMavenPluginManager) (in populatePluginFields)
- DefaultMavenPluginManager.java:630 calls ValidatingConfigurationListener.java:46 (constructor) and I think in there is the issue:
  It gets the parameters from the mojoDescriptor, checks if they are marked as required and if yes adds them to "missingParameters" without
  checking if the parameters are actually present in the parameters supplied to the "mojo".
  DefaultMavenPluginManager.java:639 then gets "missingParameters" from ValidatingConfigurationListener and turns that into a
  PluginParameterException in DefaultMavenPluginManager.java:644 (depending on if configuratorId is basic, otherwise it handles it differently in else).

{**}My conclusion{**}:
So I think the constructor of ValidatingConfigurationListener just needs to check, if the parameters marked as required are actually present
  according to its task, which includes according to JavaDoc "[...] check for required but missing parameters." and put only those actually missing in "missingParameters".
  
I assume that should solve the issue.
(When fixing it, make sure to additionally check, whether the purpose of the if/else depending on configuratorId in DefaultMavenPluginManager.java:642-653 makes sense in this context, as it seems to call a different validation in the else part.)

---

**Affects:** 3.8.6

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.