Skip to content

Commit

Permalink
Merge pull request #3090 from sparhidev/master
Browse files Browse the repository at this point in the history
Documentation updated to address #3073
  • Loading branch information
rzwitserloot committed Jan 20, 2022
2 parents 7eff9d3 + c387bf3 commit 2613f58
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion website/templates/features/NonNull.html
Expand Up @@ -11,7 +11,7 @@
</p><p>
Lombok has always treated various annotations generally named <code>@NonNull</code> on a field as a signal to generate a null-check if lombok generates an entire method or constructor for you, via for example <a href="/features/Data"><code>@Data</code></a>. However, using lombok's own <code>@lombok.NonNull</code> on a parameter or record component results in the insertion of the null-check at the top of that method.
</p><p>
The null-check looks like <code>if (param == null) throw new NullPointerException("param is marked @NonNull but is null");</code> and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit <code>this()</code> or <code>super()</code> 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 <code>if (param == null) throw new NullPointerException("param is marked non-null but is null");</code> and will be inserted at the very top of your method. For constructors, the null-check will be inserted immediately following any explicit <code>this()</code> or <code>super()</code> 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.
</p><p>
If a null-check is already present at the top, no additional null-check will be generated.
</p>
Expand Down
2 changes: 1 addition & 1 deletion website/usageExamples/NonNullExample_post.jpage
Expand Up @@ -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();
}
Expand Down

0 comments on commit 2613f58

Please sign in to comment.