Need for a @NonEmpty annotation?

48 views
Skip to first unread message

Kannan Ekanath

unread,
Apr 22, 2021, 7:54:38 AM4/22/21
to Project Lombok
Hello,
I religiously use @NonNull annotations to mark parameters that should not be null. I was wondering if people have felt enough need for a semantical @NonEmpty annotation.

The main motivation being that for Strings usually @NonNull is not good enough because strings usually come from property files/configs or from external systems (json/yaml/whatever) and they often end up as blanks or "    ". 

You can argue the same goes with collections usually nulls are difficult to handle and hence empty collections are passed. I believe this annotation will make sure it covers these scenarios as I am always checking them otherwise. 

Thoughts?
Kannan

Constantine Plotnikov

unread,
Apr 28, 2021, 1:52:41 PM4/28/21
to project...@googlegroups.com
Hi!

From a logically formal point of view, @NonEmpty should not imply @NonNull. Non-empty nullable, means that if value is not null, its length should be more than one element. It is like a shortcut for @Size(min = 1). Most utilities and java validation still imply that non-empty is non-null, so it is a composition of of @NonNull and @Size(min=1) (https://javaee.github.io/javaee-spec/javadocs/javax/validation/constraints/NotEmpty.html). To forbid the string " " the correct annotation would be @NonBlank, that theoretically also should be orthogonal to @NonNull, but it is not (https://javaee.github.io/javaee-spec/javadocs/javax/validation/constraints/NotBlank.html).

So, NonNull, NonEmpty, and NonBlank are progressively more restrictive for strings and each level of validation makes sense.

Best Regard,
Konstantin

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/7c36f63f-ed93-49f3-b9cf-8f5ce612a2fcn%40googlegroups.com.

Kannan Ekanath

unread,
Apr 28, 2021, 1:55:11 PM4/28/21
to project...@googlegroups.com
I am happy with the interpretation of this. What is the logical next step? To file an issue in Lombok (how?)

You received this message because you are subscribed to a topic in the Google Groups "Project Lombok" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/project-lombok/ieV9CKxwlb8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to project-lombo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/CACFMeKRY3GutBC93sD1v1Foc7CFoiKXTqA9qivRv%2B3dPfgDQ1A%40mail.gmail.com.


--
Regards,
Kannan Ekanath
Reply all
Reply to author
Forward
0 new messages