Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

maddi-java-openjdk: type-use annotations dropped from a nested class's field typed by the enclosing generic class

Abierto
#145 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
42/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
java, kotlin

Línea de trabajo

Start with the reduced case exercised through JavaInspectorImpl as TestNullabilityPass, then trace how nested-class field types are represented in FieldInfo.type(). Compare the enclosing-class, nested-library-type, and enclosing-generic-type cases, and inspect where ParameterizedType type-use annotations are copied or lost. Done means AS<@Nullable Object> retains the annotation for the nested Holder field and the Kotlin translation no longer produces the nullability mismatch.

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

Descripción

bug front-end:javac

In a static nested class, a field whose type is the enclosing generic class loses the type-use annotations on its type arguments. guava's Ordering:

public abstract class Ordering<T> implements Comparator<T> {
  private static final class ArbitraryOrderingHolder {
    static final Ordering<@Nullable Object> ARBITRARY_ORDERING = new ArbitraryOrdering();
  }
  ...
}

ARBITRARY_ORDERING's FieldInfo.type() arrives as Ordering<Object>, and the type argument's annotations() is empty.

Reduced, through JavaInspectorImpl as TestNullabilityPass in maddi-mod runs it:

package a.b;
import java.util.Comparator;
@java.lang.annotation.Target(java.lang.annotation.ElementType.TYPE_USE) @interface Nullable {}
abstract class AS<T> implements Comparator<T> {
    static final AS<@Nullable Object> ARBITRARY = new Arbitrary();   // AS<@Nullable Object>  (kept)
    static AS<@Nullable Object> plain;                               // AS<@Nullable Object>  (kept)
    private static final class Holder {
        static final AS<@Nullable Object> ARBITRARY = new Arbitrary(); // AS<Object>          (dropped)
    }
    static class Arbitrary extends AS<@Nullable Object> {
        public int compare(@Nullable Object a, @Nullable Object b) { return 0; }
    }
}

The same annotation is kept on:

  • a field of the outer class itself;
  • a field of the nested class typed by a library class, e.g. Comparator<@Nullable Object> in Holder.

The annotation is not needed on the @interface either: a top-level annotation type and one nested in AS give the same result.

Effect: the Kotlin translation prints internal val ARBITRARY_ORDERING: Ordering<Any> = ArbitraryOrdering(), while arbitrary(): Ordering<Any?> returns it. kotlinc reports "type mismatch: expected Ordering<Any?>, actual Ordering" (guava Ordering.kt:214).

Expected: the field's ParameterizedType carries the type-use annotations as written, as it does for the outer class's own fields.

Found while reducing guava's KotlinConf scoreboard compile errors, together with the printer session. Related: #144 (anonymous class creation types).

🤖 Generated with Claude Code

Lenguaje dominante
Java
Estrellas
1
Forks
1
Merge medio
1 h 58 min
PR fusionados (30 d)
5

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de CodeLaser/maddi

Todos los issues de CodeLaser/maddi

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.