apache / apache/maven-toolchains-plugin

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

Ouverte Adaptée aux débutants
#175 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
27
Forks
31
Métriques de merge des PR
Aucune PR mergée en 30 j

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.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Ouvrez src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java et examinez ToolchainMojo.execute() autour des lignes 58-61. Supprimez le bloc de vérification de null du paramètre toolchains requis, puis vérifiez que le plugin se construit toujours et que ses vérifications existantes passent.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
java
Domaine
build-system
Type d'issue
Refactorisation
Difficulté
1/5
Temps estimé
Moins d'une heure
Activité
Calme
Clarté
Clairement spécifiée
Accessibilité débutants
88/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.