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

   Fixes #8393
   
   ### What and why
   
   `AttachedArtifact.getVersion()` returns the version of the parent, but the 
constructor of the superclass validates its arguments, and builds the error 
message, before the parent is assigned. When the validation fails, the message 
calls `getVersion()` on a `null` parent, and a `NullPointerException` hides the 
real error. This happens for instance when a plugin calls `setVersion()` on the 
project artifact, which clears its version range, and `maven-source-plugin` 
then attaches the sources.
   
   ### How
   
   `getVersion()` falls back to the version of the superclass while the parent 
is not set. The caller now gets an `InvalidArtifactRTException` saying "The 
version cannot be empty." instead of the `NullPointerException`.
   
   ### Tests
   
   `AttachedArtifactTest` is new. One test checks that the version is the one 
of the parent, the other builds an attached artifact on a parent whose version 
range was cleared by `setVersion()`, as in the issue. The second one fails on 
master with `NullPointerException: ... because "this.parent" is null` and 
passes with the change, three runs in a row. `maven-core` passes (734 tests) 
and spotless is clean. I did not run the integration tests.
   
   ---
   
   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:
   
   - [ ] 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