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


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

Re: null checks

Newsgroups comp.lang.java.programmer
Date 2017-07-10 05:35 -0700
References (1 earlier) <ojoaip$pab$1@gioia.aioe.org> <70f5af57-8dc0-416c-b2aa-0bbbb47fc7b5@googlegroups.com> <ojobsn$rh8$1@gioia.aioe.org> <wj8y35fwauls$.t07pxjfiv3wa.dlg@40tude.net> <ojrls7$1b0t$1@gioia.aioe.org>
Message-ID <295649b6-cbf7-432f-9416-e1411fcc79c9@googlegroups.com> (permalink)
Subject Re: null checks
From Eric Douglas <e.d.programmer@gmail.com>

Show all headers | View raw


On Saturday, July 8, 2017 at 6:21:14 PM UTC-4, Arne Vajhøj wrote:
> Checks done by the Java compiler are fine, because if the byte code
> exist then I assume that it has been through a compliant Java
> compiler.
> 
> Checks done by a tool to provide input for refactoring are fine.
> You can run the tool and make some fixes and the code is going
> to be better.
> 
> Checks done by a tool to have runtime checks replaced by
> build time checks leave me with a fuzzy feeling. Will that
> tool always be run? Can I verify if it has been run?
> That is why I don't want to rely on a tool for this
> type of stuff.
> 
> Arne

I'm just talking about a public method.  I don't normally check for nulls in private method because I know where the value comes from and if it might be or should be allowed a null.  Once I compile it into a jar and someone else calls the method we have no idea.  They could decide a null ought to be acceptable and explicitly pass it, or they could pass a variable that accidentally gets assigned a null value.  I just want the method to crash as soon as possible with the "invalid parameter" exception.  Objects.requireNonNull() is now the simplest way to do that, and in this case the @NonNull appears pointless?

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