googleapis / googleapis/google-http-java-client

NULL_BOOLEAN is not compatible with Value Objects

未关闭
#2,185 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Java
星标
1.4k
派生
473
PR 合并指标
30 天内没有已合并 PR

描述

`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:

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

Possible fixes:

* Introduce a new API like `JsonNullable` to replace the use of `NULL_BOOLEAN`
* Maintain a set of explicitly set fields, that could be queried instead of relying on sentinel values.

贡献指南

打开贡献指南

调研方向

Start in google-http-client/src/main/java/com/google/api/client/util/Data.java, especially Data.isNull and NULL_BOOLEAN, and reproduce the assertions shown in the issue with the JDK 28 value-class preview. Compare the two proposed approaches; done means legitimate Boolean, Integer, and Long values no longer return true from Data.isNull while absent and explicit-null tracking remains correct.

由索引模型根据 Issue 内容生成。

评估

技术栈
java
领域
api
Issue 类型
缺陷
难度
5/5
预计耗时
一周以上
活跃度
冷清
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。