Skip to content

Remove runtime validation checks for builders with JSpecify support #897

@sjohnr

Description

@sjohnr

Context

Previously, with the JSpecify support (generateJSpecifyAnnotations = true), we generated Objects.requireNonNull checks for non-nullable fields in the build() method for builders. This was an attempt to prevent bypassing the all-args constructor and using a builder to build a partially hydrated object. Unfortunately, this is too strict in practice because object types are rarely fully populated. This is especially true in tests where mocking small parts of an object graph is common, but can easily be true in data fetcher scenarios as well. We should not add runtime-level checking along with this feature.

Solution

Simply remove the runtime checks and allow the build() method to succeed even with a partially hydrated object.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions