From a0b901c3c04d0377f495a9da853196a3b0433eae Mon Sep 17 00:00:00 2001
From: Reinier Zwitserloot
Lombok has always treated any annotation 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
. Now, however, using lombok's own @lombok.NonNull
on a parameter results in the insertion of just the null-check statement inside your own method or constructor.
- The null-check looks like if (param == null) throw new NullPointerException("param");
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.
+ 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.
If a null-check is already present at the top, no additional null-check will be generated.
@@ -23,7 +23,7 @@lombok.nonNull.exceptionType
= [NullPointerException
| IllegalArgumentException
] (default: NullPointerException
).
if
statement, by default, a java.lang.NullPointerException
will be thrown with the field name as the exception message. However, you can use IllegalArgumentException
in this configuration key to have lombok throw that exception, with 'fieldName is null' as exception message.
+ When lombok generates a null-check if
statement, by default, a java.lang.NullPointerException
will be thrown with 'field name is marked @NonNull but is null' as the exception message. However, you can use IllegalArgumentException
in this configuration key to have lombok throw that exception with this message instead.
lombok.nonNull.flagUsage
= [warning
| error
] (default: not set)