Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#145 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
java, kotlin
Lĩnh vực
compilers, devtools, testing-qa

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Java
Star
1
Fork
1
Merge trung bình
1 giờ 58 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của CodeLaser/maddi

Tất cả issue của CodeLaser/maddi

Issue tương tự

Thêm issue về Java

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.