Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: null checks Date: Fri, 7 Jul 2017 12:53:15 -0400 Organization: A noiseless patient Spider Lines: 38 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: 8bit Injection-Date: Fri, 7 Jul 2017 16:49:33 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="efaa7c448619693266938c9656a689a7"; logging-data="7030"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/st6yIxMXOQ4QmjVBFuXVS" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: <70f5af57-8dc0-416c-b2aa-0bbbb47fc7b5@googlegroups.com> Content-Language: en-US Cancel-Lock: sha1:Nmez478/Rn/7WwungwJpjsDxnIc= Xref: csiph.com comp.lang.java.programmer:36818 On 7/7/2017 11:54 AM, Eric Douglas wrote: > On Friday, July 7, 2017 at 11:50:05 AM UTC-4, Arne Vajhøj wrote: >> >> I am not sure that I understand the question. >> >> Annotations can be used by compilers or check tools to >> issue warnings/errors and by AOP tools to insert runtime checks >> automatically. >> >> A runtime check is just a piece of code that does a runtime check. >> >> Two completely different purposes. >> >> Arne > > So what are you trying to say, if you need a parameter to never be null use both the @NonNull and the new Objects.requireNonNull()? > Is the assert verb still necessary or useful? See Arne's response. I'll just add that `assert' is not suitable for sanity-checking arguments to public methods, for the very simple reason that I T C A N B E T U R N E D O F F ... and in fact *is* turned off by default unless you ask the JVM to enable it. `assert' is for catching logic errors in the code, not invalid data from "external sources." What counts as "external" is a bit fuzzy, and some arguments (particularly of `private' methods) may well count as "internal" and be appropriate for `assert' tests. But if you require a reference to be non-null or a number to be non-negative or a String to be exactly seven characters long, you should enforce your requirement with something stronger than `assert'. -- esosman@comcast-dot-net.invalid Twelve hundred ninety-three days to go.