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

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

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

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

評価

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

調査の方向性

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.

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

説明

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.

主要言語
Java
スター
26.9k
フォーク
7.8k
平均マージ
2日 10時間
マージ済み PR(30日)
180

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

OpenAPITools/openapi-generator のほかの issue

OpenAPITools/openapi-generator の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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