Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36843

Re: null checks

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 <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: null checks
Date Sun, 9 Jul 2017 13:10:35 +0200
Lines 29
Message-ID <eseh9cFk6shU1@mid.individual.net> (permalink)
References <fb0314ea-bd97-4348-8af1-3ac9f9f46bdc@googlegroups.com> <ojoaip$pab$1@gioia.aioe.org> <70f5af57-8dc0-416c-b2aa-0bbbb47fc7b5@googlegroups.com> <ojobsn$rh8$1@gioia.aioe.org>
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 <ojobsn$rh8$1@gioia.aioe.org>
Content-Language en-US
Xref csiph.com comp.lang.java.programmer:36843

Show key headers only | View raw


On 07.07.2017 18:12, Arne Vajhøj 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 
invoked will trigger a NPE.  I tend to add explicit null checks

* For methods when an argument is assigned a member variable which by 
class invariant must not be null and which does not invoke methods on 
the argument.  This is often the case for constructors.
* If the automatic null check on method invocation comes too late (e.g. 
when the work of the method is half through at the time and would 
require rolling back work).  I also like to do argument checks like 
these before a synchronized block is entered.

Kind regards

	robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

null checks Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 08:03 -0700
  Re: null checks Arne Vajhøj <arne@vajhoej.dk> - 2017-07-07 11:49 -0400
    Re: null checks Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 08:54 -0700
      Re: null checks Arne Vajhøj <arne@vajhoej.dk> - 2017-07-07 12:12 -0400
        Re: null checks Eric Douglas <e.d.programmer@gmail.com> - 2017-07-07 10:16 -0700
        Re: null checks Joerg Meier <joergmmeier@arcor.de> - 2017-07-08 22:33 +0200
          Re: null checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-07-08 21:14 +0000
            Re: null checks Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-08 17:51 -0400
              Re: null checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-07-08 22:26 +0000
            Re: null checks Arne Vajhøj <arne@vajhoej.dk> - 2017-07-08 18:28 -0400
            Re: null checks Joerg Meier <joergmmeier@arcor.de> - 2017-07-25 07:26 +0200
              Re: null checks Martin Gregorie <martin@address-in-sig.invalid> - 2017-07-25 12:12 +0000
          Re: null checks Arne Vajhøj <arne@vajhoej.dk> - 2017-07-08 18:20 -0400
            Re: null checks Eric Douglas <e.d.programmer@gmail.com> - 2017-07-10 05:35 -0700
        Re: null checks Robert Klemme <shortcutter@googlemail.com> - 2017-07-09 13:10 +0200
      Re: null checks Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-07 12:53 -0400
        Re: null checks lewbloch@gmail.com - 2017-07-26 11:16 -0700
          Re: null checks Eric Douglas <e.d.programmer@gmail.com> - 2017-07-26 11:40 -0700
            Re: null checks Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-07-26 16:40 -0400
            Re: null checks lewbloch@gmail.com - 2017-07-28 18:47 -0700
  Re: null checks Wayne <wayne@nospam.invalid> - 2017-07-07 16:24 -0400
  Re: null checks Joerg Meier <joergmmeier@arcor.de> - 2017-07-08 22:32 +0200
  Re: null checks Lothar Kimmeringer <news201705@kimmeringer.de> - 2017-07-09 15:59 +0200
    Re: null checks Arne Vajhøj <arne@vajhoej.dk> - 2017-07-11 20:30 -0400

csiph-web