apache / apache/maven-toolchains-plugin

Dead code: unreachable null check on @Parameter(required=true) in ToolchainMojo

Open Beginner friendly
#175 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
27
Forks
31
PR merge metrics
No merged PRs in 30d

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`

https://github.com/apache/maven-toolchains-plugin/blob/master/src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java#L58-L61

## Code

```java
@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

1. `@Parameter(required = true)` means Maven will fail the build with an error if the `toolchains` configuration is not provided
2. The null check guard is unreachable because execution never reaches the mojo if a required parameter is missing
3. The comment `// should not happen since parameter is required...` confirms the developer knew this was dead code
4. 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.

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

Tech stack
java
Domain
build-system
Issue type
Refactor
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.