Victor is a Java Champion, Speaker, and Independent Trainer with impressive experience: thousands of developers in over 40 companies followed his training or live-webinars until now. He is the founder of Bucharest Software Craftsmanship Community, one of the largest developer communities in Romania today, sharing his love for Clean Code, Refactoring, and Unit Testing every month.
The terrible NullPointerException (NPE for short) is the most frequent Java exception occurring in production, according to a 2016 study. In this article we’ll explore the main techniques to fight it: the self-validating model and the Optional wrapper.
You should consider upgrading your entity model to either reject a null via self-validation or present the nullable field via a getter that returns Optional. The effort of changing the getters of the core entities in your app is considerable, but along the way, you may find many dormant NPEs.V. Rentea