Status
Accepted
Context
Returning null for collections increases the likelihood of NullPointerException errors and requires defensive coding with null-checks. This makes the code harder to maintain and more error-prone.
Decision
- Methods, including those generated by
@Getter, must not returnnullfor collection types. - If the underlying property of a collection getter is
null, the method should return an empty collection (e.g.,emptyList()). - Pay extra attention to
nullvalues received from clients (e.g., REST API requests) - make sure the DTOs don’t returnnullfor collections
Consequences
Positive
- Eliminates many null-checks, simplifying code and reducing errors.
- Encourages robust, defensive programming practices.
Negative
- Requires consistent developer discipline to enforce this rule.