-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Missed null checks in record constructor when non-Lombok annotations are used #3743
Comments
Came here to raise this exact same issue :) Did get as far as writing a smaller test case for it, so will share that in case it's useful. import org.springframework.lang.NonNull;
@Test
void checkNonNull() {
assertThatThrownBy(() -> TestClass.builder().build())
.describedAs("Checking class has non-null fields")
// passes
.isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> TestRecord.builder().build())
.describedAs("Checking record has non-null fields")
// fails with Expecting code to raise a throwable.
.isInstanceOf(NullPointerException.class);
}
@Builder
public static class TestClass {
@org.springframework.lang.NonNull
private final String value;
}
@Builder
record TestRecord(@org.springframework.lang.NonNull String value) {
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
Lombok does not generate record constructor with nullability checks for a record with annotated fields - if non-Lombok annotations are used for. The following annotations are affected:
When same annotations are used on fields of data class (annotated with @ Data and @ Builder) - constructor with nullability checks is generated properly.
To Reproduce
Please see the following test project. It contains all required annotated classes and unit tests.
Expected behavior
Lombok should generate record constructor with nullability checks for a record with annotated fields even if non-Lombok annotations are used for.
Version info (please complete the following information):
Additional context
The text was updated successfully, but these errors were encountered: