Dead code: unreachable null check on @Parameter(required=true) in ToolchainMojo
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 88/100
- Issue type
- Refactor
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- java
- Domain
- build-system
Research direction
Open src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java and inspect ToolchainMojo.execute() around lines 58-61. Remove the null-check block for the required toolchains parameter, then verify the plugin still builds and its existing checks pass.
Written by the indexing model from the issue text.
Description
Summary
ToolchainMojo.execute() contains a null check on the toolchains field that is annotated with @Parameter(required = true). Maven enforces required parameters before the mojo executes, making this check dead code.
Location
ToolchainMojo.java:58-61
Code
@Parameter(required = true)
private ToolchainsRequirement toolchains;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (toolchains == null) {
// should not happen since parameter is required...
getLog().warn("No toolchains requirements configured.");
return;
}
// ...
}
Problem
@Parameter(required = true)means Maven will fail the build with an error if thetoolchainsconfiguration is not provided- The null check guard is unreachable because execution never reaches the mojo if a required parameter is missing
- The comment
// should not happen since parameter is required...confirms the developer knew this was dead code - If it did somehow execute, silently returning with just a warning is the wrong behavior for a missing required config
Impact
Dead code increases maintenance burden and gives a false impression that the plugin handles missing configuration gracefully (it doesn't - Maven handles it beforehand).
Suggested Fix
Remove the null check block entirely.
- Dominant language
- Java
- Stars
- 27
- Forks
- 31
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/maven-toolchains-plugin
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
All issues in apache/maven-toolchains-plugin
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100