[BUG][JAVA] Generated code still missing many @Nullable annotations

Đang mở
#25,536 0 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
35/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
Lĩnh vực
tooling

Hướng nghiên cứu

Start by generating a Java model with the useJspecify option enabled, using a spec like the one in #23656, and compare the output with the snippet in the issue. The fix belongs in the Java model templates that emit @NullMarked code, which you can locate by searching for the useJspecify flag. Done means the listed members (the additionalProperties field and getter, getAdditionalProperty, equals, toIndentedString) carry @Nullable where they can be null, and a nullability checker reports no new errors.

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

Mô tả

Issue: Bug
Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating a Java model with useJspecify, the package is @NullMarked but many @Nullable annotations are missing.

  private Map<String, Object> additionalProperties;  // <-- both Map and possibly Object should be @Nullable

  @JsonAnySetter
  public TestModel putAdditionalProperty(String key, Object value) {
    if (this.additionalProperties == null) {  // <-- it handles the Map being null here
        this.additionalProperties = new HashMap<String, Object>();
    }

  @JsonAnyGetter
  public Map<String, Object> getAdditionalProperties() {  // <-- matching annotation needed here
    return additionalProperties;  // <-- as it could return null
  }

  public Object getAdditionalProperty(String key) {  // <-- missing @Nullable
    if (this.additionalProperties == null) {
        return null;  // <-- for this return
    }
    return this.additionalProperties.get(key);  // <-- and possibly here if values can be null
  }

  @Override
  public boolean equals(Object o) {  // <-- should be @Nullable
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {  // <-- as per Object.equals spec, it handles nulls
      return false;
    }
    // ...
  }

  private String toIndentedString(Object o) {  // <-- ditto
      return o == null ? "null" : o.toString().replace("\n", "\n    ");
  }
openapi-generator version

7.27.0

OpenAPI declaration file content or url

See #23656

Generation Details

See #23656

Steps to reproduce

See #23656

Related issues/PRs

#23656

Suggest a fix

Add @Nullable in the correct places in the templates.

Scan all generated code with a nullability checker that can find further instances of this error.

Ngôn ngữ chính
Java
Star
26.9k
Fork
7.8k
Merge trung bình
2 ngày 10 giờ
Pull request đã merge (30 ngày)
180

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

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

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 OpenAPITools/openapi-generator

Tất cả issue của OpenAPITools/openapi-generator

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.