From a2df6e6cc442fb1377e58aa0aeeece143e6ce660 Mon Sep 17 00:00:00 2001 From: Shubhendu Parhi <86868701+sparhidev@users.noreply.github.com> Date: Thu, 20 Jan 2022 13:31:24 +0530 Subject: Updated documentation to resolve #3073 --- website/templates/features/NonNull.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/templates/features/NonNull.html b/website/templates/features/NonNull.html index 57aa62fe..cccc69fa 100644 --- a/website/templates/features/NonNull.html +++ b/website/templates/features/NonNull.html @@ -11,7 +11,7 @@

Lombok has always treated various annotations generally named @NonNull on a field as a signal to generate a null-check if lombok generates an entire method or constructor for you, via for example @Data. However, using lombok's own @lombok.NonNull on a parameter or record component results in the insertion of the null-check at the top of that method.

- The null-check looks like if (param == null) throw new NullPointerException("param is marked @NonNull but is null"); and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit this() or super() calls. For record components, the null-check will be inserted in the 'compact constructor' (the one that has no argument list at all), which will be generated if you have no constructor. If you have written out the record constructor in long form (with parameters matching your components exactly), then nothing happens - you'd have to annotate the parameters of this long-form constructor instead. + The null-check looks like if (param == null) throw new NullPointerException("param is marked non-null but is null"); and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit this() or super() calls. For record components, the null-check will be inserted in the 'compact constructor' (the one that has no argument list at all), which will be generated if you have no constructor. If you have written out the record constructor in long form (with parameters matching your components exactly), then nothing happens - you'd have to annotate the parameters of this long-form constructor instead.

If a null-check is already present at the top, no additional null-check will be generated.

-- cgit From c387bf3a920975622dd7fc5431f388dd1fd4c952 Mon Sep 17 00:00:00 2001 From: Shubhendu Parhi <86868701+sparhidev@users.noreply.github.com> Date: Thu, 20 Jan 2022 13:41:52 +0530 Subject: Updated NonNullExample snippet to address #3073 --- website/usageExamples/NonNullExample_post.jpage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/usageExamples/NonNullExample_post.jpage b/website/usageExamples/NonNullExample_post.jpage index bb67b3f6..ff3c2dc3 100644 --- a/website/usageExamples/NonNullExample_post.jpage +++ b/website/usageExamples/NonNullExample_post.jpage @@ -6,7 +6,7 @@ public class NonNullExample extends Something { public NonNullExample(@NonNull Person person) { super("Hello"); if (person == null) { - throw new NullPointerException("person is marked @NonNull but is null"); + throw new NullPointerException("person is marked non-null but is null"); } this.name = person.getName(); } -- cgit