Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#145 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
42/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
java, kotlin

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Java
スター
1
フォーク
1
平均マージ
1時間 58分
マージ済み PR(30日)
5

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

CodeLaser/maddi のほかの issue

CodeLaser/maddi の issue をすべて見る

似ている issue

Java の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。