NULL_BOOLEAN is not compatible with Value Objects

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
静か
技術スタック
java
領域
api

調査の方向性

google-http-client/src/main/java/com/google/api/client/util/Data.java から始め、特に Data.isNull と NULL_BOOLEAN を確認し、JDK 28 の value-class preview で issue に示されている Assertions を再現してください。提案されている 2 つのアプローチを比較してください。Boolean、Integer、Long の正当な値が Data.isNull で true を返さなくなり、不在値と明示的な null の追跡が引き続き正しく行われれば完了です。

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

説明

google-http-client uses sentinel objects like NULL_BOOLEAN to distinguish between fields being absent and explicitly set to null:

https://github.com/googleapis/google-http-java-client/blame/95fac312dd743a94fb28532ef8a50d374e6481ad/google-http-client/src/main/java/com/google/api/client/util/Data.java#L48-L49

Those sentinel fields are using deprecated constructors like new Boolean(true) (the deprecation warnings were suppressed in https://github.com/googleapis/google-http-java-client/pull/1215).

JDK 28 introduces a preview of the value classes feature (https://openjdk.org/jeps/401). With JEP 401 boxed primitive classes like Boolean and Integer become value classes that don't have identity, so instance are compared by value:

  • new Boolean(true) == Boolean.TRUE will evaluate to true
  • new Integer(0) == Integer.valueOf(0) will evaluate to true

This causes google-http-client's Data.isNull(object) to return true for legitimate values.

With JEP 401, assertions like these will start to fail:

    assertThat(Data.isNull(true)).isFalse(); 
    assertThat(Data.isNull(0)).isFalse();
    assertThat(Data.isNull(0L)).isFalse();

Possible fixes:

  • Introduce a new API like JsonNullable<Boolean> to replace the use of NULL_BOOLEAN
  • Maintain a set of explicitly set fields, that could be queried instead of relying on sentinel values.
主要言語
Java
スター
1.4k
フォーク
476
平均マージ
10時間 47分
マージ済み PR(30日)
3

環境構築

はじめの一歩

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

googleapis/google-http-java-client のほかの issue

googleapis/google-http-java-client の issue をすべて見る

似ている issue

Java の issue をもっと見る

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

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