Skip to content
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

Open
a--v--k opened this issue Sep 10, 2024 · 1 comment

Comments

@a--v--k
Copy link

a--v--k commented Sep 10, 2024

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:

  • Google Findbugs annotations
  • Jakarta validation annotations
  • Jetbrains annotations
  • Spring annotations

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):

  • Lombok version - 1.18.34
  • Lombok gradle plugin version - 8.10
  • Eclipse Temurin JDK 21.0.4
  • Gradle 8.9

Additional context

@GregDThomas
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants