Skip to content

Generate required fields constructor when JSpecify is enabled#910

Merged
sjohnr merged 2 commits intoNetflix:masterfrom
sar9ho:jspecify-required-fields-constructor
Feb 3, 2026
Merged

Generate required fields constructor when JSpecify is enabled#910
sjohnr merged 2 commits intoNetflix:masterfrom
sar9ho:jspecify-required-fields-constructor

Conversation

@sar9ho
Copy link
Contributor

@sar9ho sar9ho commented Dec 21, 2025

Adds a “required fields” constructor for Java types when generateJSpecifyAnnotations = true.

Behavior:

For testing, I added some targeted cases in CodeGenTest ^

Fixes #900
Fixes #901

Copy link
Contributor

@sjohnr sjohnr left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @sar9ho! This looks like a good start, but I have some suggestions for changes below.

* Add tests for JSpecify constructor generation based on field nullability
* Generated required fields constructor when JSpecify enabled
* Fix ktlint formatting in DataTypeGenerator
* fixed ktlint formatting in CodeGenTest
* gate required-fields constructor behind javaGenerateAllConstructor + avoid duplicates
* added tests for required-fields constructor behavior
sjohnr added a commit to sar9ho/dgs-codegen that referenced this pull request Feb 3, 2026
* expand conditional for generating required-args constructor
  to check requiredFields.size < 256 even if fields is not
@sjohnr sjohnr force-pushed the jspecify-required-fields-constructor branch from d1433e2 to b62e95d Compare February 3, 2026 21:29
* expand conditional for generating required-args constructor
  to check requiredFields.size < 256 even if fields is not
@sjohnr sjohnr force-pushed the jspecify-required-fields-constructor branch from b62e95d to 310dd4b Compare February 3, 2026 22:04
@sjohnr sjohnr merged commit 8fad3cd into Netflix:master Feb 3, 2026
2 checks passed
@sjohnr
Copy link
Contributor

sjohnr commented Feb 3, 2026

Thanks @sar9ho! Sorry for the delay. I have merged this to master. I did make a polish commit to improve one of the checks slightly (256 fields) but everything else looked good. I think we can revisit adding a separate flag if it gets requested, but I think this is a good change as-is to improve the constructor situation when JSpecify is enabled.

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

Labels

None yet

Projects

None yet

2 participants

Comments