apache / apache/maven-toolchains-plugin

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

Abierto Apto para principiantes
#175 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
27
Forks
31
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## 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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Abre src/main/java/org/apache/maven/plugins/toolchain/ToolchainMojo.java e inspecciona ToolchainMojo.execute() alrededor de las líneas 58-61. Elimina el bloque de comprobación de null del parámetro toolchains requerido y, después, verifica que el plugin siga compilándose y que sus comprobaciones existentes pasen.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
build-system
Tipo de issue
Refactorización
Dificultad
1/5
Tiempo estimado
Menos de una hora
Estado de actividad
Tranquilo
Claridad
Bien especificado
Aptitud para principiantes
88/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.