Path: csiph.com!feeder.erje.net!2.eu.feeder.erje.net!news-2.dfn.de!news.dfn.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: null checks Date: Sun, 9 Jul 2017 13:10:35 +0200 Lines: 29 Message-ID: References: <70f5af57-8dc0-416c-b2aa-0bbbb47fc7b5@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: individual.net CeHxHIYyj0X/xJCGjSZ6iwO2MLdmi6hJcVjMfEfbdVSu/EAcg= Cancel-Lock: sha1:wHo77oP5OSJGctp3DJ+RbOp/qX8= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Xref: csiph.com comp.lang.java.programmer:36843 On 07.07.2017 18:12, Arne Vajh=C3=B8j wrote: > You need to choose between approaches: > 1) Annotate and let IDE/checktool give you warnings during dveelopment > 2) Make a runtime check > A) Insert the check code manually > B) Annotate and weave the check code in via AOP > I think approach 2A is the simple safe approach. Often the manual insertion is not necessary because the first method=20 invoked will trigger a NPE. I tend to add explicit null checks * For methods when an argument is assigned a member variable which by=20 class invariant must not be null and which does not invoke methods on=20 the argument. This is often the case for constructors. * If the automatic null check on method invocation comes too late (e.g.=20 when the work of the method is half through at the time and would=20 require rolling back work). I also like to do argument checks like=20 these before a synchronized block is entered. Kind regards robert --=20 remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/