<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Victor Rentea on foojay.io - Friends of OpenJDK</title><link>https://foojayio.github.io/website/today/author/victor-rentea/</link><description>Articles written by Victor Rentea on foojay.io - Friends of OpenJDK</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 22 Dec 2020 10:14:41 +0000</lastBuildDate><atom:link href="https://foojayio.github.io/website/today/author/victor-rentea/index.xml" rel="self" type="application/rss+xml"/><item><title>How to Avoid NullPointerException in Java Code</title><link>https://foojayio.github.io/website/today/avoiding-nullpointerexception/</link><pubDate>Tue, 22 Dec 2020 10:14:41 +0000</pubDate><guid>https://foojayio.github.io/website/today/avoiding-nullpointerexception/</guid><description>&lt;p&gt;The terrible &lt;code&gt;NullPointerException&lt;/code&gt; (NPE for short) is the most frequent Java exception occurring in production, according to &lt;a href="https://www.overops.com/blog/the-top-10-exceptions-types-in-production-java-applications-based-on-1b-events/" target="_blank" rel="noopener noreferrer"&gt;a 2016 study&lt;/a&gt;
. In this article we&amp;rsquo;ll explore the main techniques to fight it: the self-validating model and the &lt;code&gt;Optional&lt;/code&gt; wrapper.&lt;/p&gt;
&lt;h2 id="h2-0-self-validating-model"&gt;Self-Validating Model&lt;/h2&gt;
&lt;p&gt;Imagine a business rule: every Customer has to have a birth date set. There are a number of ways to implement this constraint: validating the user data on the create and update use-cases, enforcing it via &lt;code&gt;NOT NULL&lt;/code&gt; database constraint and/or implementing the null-check right in the constructor of the Customer entity. In this article we&amp;rsquo;ll explore the last one.&lt;/p&gt;</description></item></channel></rss>