NULL_BOOLEAN is not compatible with Value Objects

Open
#2,185 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Quiet
Tech stack
java
Domain
api

Research direction

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.

Written by the indexing model from the issue text.

Description

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.
Dominant language
Java
Stars
1.4k
Forks
476
Avg merge
10h 47m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-http-java-client

All issues in googleapis/google-http-java-client

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.