When using Lombok's @Value
annotation in a Java class, Eclipse may show an error message saying "@NonNullByDefault
is applied to the module default package" or "@NonNullByDefault
in package-info.java does not affect source files" or similar.
This error occurs because @NonNullByDefault
is a Java 8 annotation that specifies that all parameters and return values in a package or module are non-null by default unless explicitly annotated otherwise. However, Lombok's @Value
annotation generates a constructor and getters that do not use nullability annotations, so Eclipse doesn't know whether the generated code is supposed to be non-null or nullable by default.
To resolve this error, you can add @NonNull
annotations to the fields of the Lombok class, or annotate the Lombok class with @lombok.NonNull
, or use @Nullable
annotations to denote nullable fields or arguments. Another solution would be to explicitly declare @NonNullByDefault
at the top of the file or in the package-info.java
file.
For example, if you want all fields in a package to be assumed as non-null by default, you can add @NonNullByDefault
to the package-info.java
file like this:
@NonNullByDefault
package com.example;
import org.eclipse.jdt.annotation.NonNullByDefault;
This will tell Eclipse that all fields in the com.example
package are non-null by default, and the @Value
-annotated Lombok classes in that package will not trigger the error message.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-03 20:08:21 +0000
Seen: 7 times
Last updated: Jul 03 '23
How can the rejection of the class text_plain from JavaMail API due to a VerifyError be confirmed?
What is the process for generating a dynamic subdomain/URL using vue.js?
How can the style of the loader be modified while the form submission is being processed?
I'm attempting to develop a Javascript-based comments section for my website.
What are some feasible methods to enable MIDI file playback on a web browser?
How can I resolve the issue of being unable to use Fetch to POST an array of Selected Checkboxes?
What is the method to hide the scroll button when reaching the bottom?
What is the process of using a custom nunjucks filter to filter collections in an eleventy template?