Skip to content

Adopt jspecify + NullAway null-checking on fdb-relational-jdbc - #4533

Draft
arnaud-lacurie wants to merge 1 commit into
apple/arnaud-lacurie/jspecify-nullaway/grpcfrom
apple/arnaud-lacurie/jspecify-nullaway/jdbc
Draft

Adopt jspecify + NullAway null-checking on fdb-relational-jdbc#4533
arnaud-lacurie wants to merge 1 commit into
apple/arnaud-lacurie/jspecify-nullaway/grpcfrom
apple/arnaud-lacurie/jspecify-nullaway/jdbc

Conversation

@arnaud-lacurie

@arnaud-lacurie arnaud-lacurie commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Second of a two-PR stack adopting jspecify + NullAway null-checking — stacked on #4532 (fdb-relational-grpc). Same treatment applied to fdb-relational-jdbc. See inline comments for specific findings.

Companion change to the fdb-relational-grpc null-checking adoption,
stacked on that branch. Same treatment: jspecify + NullAway wired via
net.ltgt.errorprone, scoped to this module only; the
com.apple.foundationdb.relational.jdbc package is marked @NullMarked;
javax.annotation.Nonnull/Nullable usages replaced with jspecify's
@nullable.

Compiling with NullAway surfaced several previously undocumented
nullable fields/returns (JDBCRelationalConnection's serverConnection/
closeable/schema, JDBCRelationalStatement's currentResultSet,
StatefulServerConnection's requestSender) and one latent bug: schema
being null (no schema set yet) was passed straight into a protobuf
StatementRequest/InsertRequest builder that expects a String, which
would have NPE'd inside protobuf rather than failing clearly at the
call site; now coerced to "" explicitly at all four call sites.

executeGet/executeScan keep their existing (pre-jspecify)
@SpotBugsSuppressWarnings("NP_NONNULL_RETURN_VIOLATION") — they
genuinely violate the @nonnull contract of
RelationalDirectAccessStatement today, "temporary until implemented";
adding jspecify @nullable there would conflict with the @nonnull
declared on the interface they override, so NullAway is suppressed at
the same two sites with the same justification instead.

@arnaud-lacurie arnaud-lacurie left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline notes for the jspecify + NullAway findings mentioned in the PR description.

.setSql(sql)
.setDatabase(getDatabase()) // TODO: for transactional execution these are not required
.setSchema(getSchema())
.setSchema(Objects.requireNonNullElse(getSchema(), ""))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latent bug caught by NullAway: schema is null before one is set, but was being passed straight into a protobuf builder's setSchema(String), which NPEs on null input. Coerced to "" here and at the other three call sites (below, and in JDBCRelationalStatement) rather than deep inside generated protobuf code.

.setDataResultSet(TypeConversion.toResultSetProtobuf(data))
.setDatabase(getDatabase())
.setSchema(getSchema())
.setSchema(Objects.requireNonNullElse(getSchema(), ""))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same null-schema-into-protobuf-setter fix as above.

.setKeySet(TypeConversion.toProtobuf(keySet))
.setDatabase(this.connection.getDatabase())
.setSchema(this.connection.getSchema())
.setSchema(Objects.requireNonNullElse(this.connection.getSchema(), ""))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same null-schema-into-protobuf-setter fix as in JDBCRelationalConnection.

.setKeySet(TypeConversion.toProtobuf(keySet))
.setDatabase(this.connection.getDatabase())
.setSchema(this.connection.getSchema())
.setSchema(Objects.requireNonNullElse(this.connection.getSchema(), ""))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same null-schema-into-protobuf-setter fix, fourth and last call site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build improvement Improvement to the build system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant