Return-Path: X-Original-To: apmail-commons-dev-archive@www.apache.org Delivered-To: apmail-commons-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C35971152C for ; Tue, 13 May 2014 15:47:42 +0000 (UTC) Received: (qmail 98796 invoked by uid 500); 13 May 2014 15:21:02 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 98692 invoked by uid 500); 13 May 2014 15:21:02 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 98684 invoked by uid 99); 13 May 2014 15:21:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 May 2014 15:21:02 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of garydgregory@gmail.com designates 209.85.219.43 as permitted sender) Received: from [209.85.219.43] (HELO mail-oa0-f43.google.com) (209.85.219.43) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 May 2014 15:20:58 +0000 Received: by mail-oa0-f43.google.com with SMTP id l6so571928oag.2 for ; Tue, 13 May 2014 08:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=6A5aD/GBD2dTbhx6MNJY5w3Fg27beroOFzVz1xZsbxc=; b=zjAqwHvEpioGpsjxmtuR5mdPdeKxbe2rFdKQYq+Zm3ioeuGsljPnLiyZJpymTe5PBg MN5TSkfhyB2FxqUB783ELnSnmbVzLrIjfZ+Vkm7rTs2x3+2kd1fjwkK+1PoAwyiLYgHF PE2bA31+8IkzhkY1EwHQQukoYCmCIr9RlWtVoRAxq+15rr4AtpQuZOAAVWKsHqWdObgo MIqWA3GbC9d7qE8PFb8QGqKUj5cTBVvv4CKIAL/OtIyjJBZ4ulAufa0sgfeaW0aDWbSU UzFLOoqZR7grru+KeRSRW/5N4mg9WTree68cSAgiicTQ4eJ2l9GEq7PYcGlfVw3AM7lw 5LQw== MIME-Version: 1.0 X-Received: by 10.182.40.201 with SMTP id z9mr42454582obk.45.1399994437790; Tue, 13 May 2014 08:20:37 -0700 (PDT) Received: by 10.60.48.40 with HTTP; Tue, 13 May 2014 08:20:37 -0700 (PDT) In-Reply-To: <5BEA9715-F6BC-4F3B-812E-64D1A500A3D6@dslextreme.com> References: <53693E0A.5030808@gmx.net> <5BEA9715-F6BC-4F3B-812E-64D1A500A3D6@dslextreme.com> Date: Tue, 13 May 2014 11:20:37 -0400 Message-ID: Subject: Re: [lang] From: Gary Gregory To: Commons Developers List Content-Type: multipart/alternative; boundary=001a11c33b0226f32b04f9499b5c X-Virus-Checked: Checked by ClamAV on apache.org --001a11c33b0226f32b04f9499b5c Content-Type: text/plain; charset=UTF-8 On Thu, May 8, 2014 at 12:24 AM, Ralph Goers wrote: > I have to say that if you look at the JDK for examples of how to code Java > correctly you will be disappointed. There are lots and lots of classes > that are really bad. > Sadly, you need experience to pick and choose what guidelines to follow from the JDK's own source. I'm amazed at the lack of changes and evolution in some classes. Some code looks like it was last edited in a 40 char wide stone tablet :) Gary > Ralph > > > On May 6, 2014, at 2:54 PM, Paul Benedict wrote: > > > This is not a matter of law. If Oracle/Sun set a direction on how to use > > NPE, it's a really good idea to follow them -- even if you don't agree, > do > > it for the sake of consistency. I don't think using IAE is somehow > "better" > > Java than what they are doing. And I give weight to what Joshua said > > because he's a former architect of that company. Lang3 was designed to > > throw NPE on invalid null arguments because that's what the gurus, like > he, > > in our industry who publish "best practices" say it should. If your > opinion > > bears greater weight than those set forth the best practices, then you > win, > > but I don't advocate going back to IAE for nulls for the reasons stated. > > > > > > > > > > Cheers, > > Paul > > > > > > On Tue, May 6, 2014 at 4:40 PM, Duncan Jones > wrote: > > > >> On 6 May 2014 22:27, "Michael Osipov" <1983-01-06@gmx.net> wrote: > >>> > >>> Am 2014-05-06 15:27, schrieb Benedikt Ritter: > >>> > >>>> Hi Thiago, > >>>> > >>>> > >>>> 2014-05-06 14:53 GMT+02:00 Thiago Andrade : > >>>> > >>>>> Hello people, > >>>>> > >>>>> Analizing the JIRA issue > >> https://issues.apache.org/jira/browse/LANG-1008the > >>>>> contributors noticed that NumberUtils.max/min methods all have the > same > >>>>> problem: > >>>>> They all throw an IllegalArgumentException when according to the > >> official > >>>>> documentation (Oracle|Sun) says that a NullPointerException must be > >> thrown > >>>>> when an argument must not be null. > >>>>> > >>>> > >>>> This is not a problem imho. It is a question of API design. I don't > now > >> an > >>>> offical documentation that say when IAE or NPE _must_ be thrown. > >> Sun/Oracle > >>>> at some point decided to throw NPE when ever a null reference is > passed > >> to > >>>> a method that doesn't accept null inputs. I don't feel this is right, > >> since > >>>> a null input is also an illegal argument. Why make a differenciation? > >> IMHO > >>>> NPE should be reserved to the JVM, when a method is called on a null > >>>> reference, but that's just my opinion. > >>> > >>> > >>> It *is* a problem because NullPointerException and > >> IllegalArgumentException have concrete semantics layed out in the JDK's > >> Javadocs. If you see how both are used in the JDK, you see that NPE and > IAE > >> are used properly and there is no such restriction to the JDK only. If > you > >> aread Effective Java, you'll see that you *have to* use NPE if a null > >> argument is passed. One might remember the NullArgumentException back in > >> Lang 2, it was removed because it is imperative to use NPE instead. > >> > >> Effective Java is a great book, but don't confuse Joshua's advice with > law. > >> > >>> > >>> Moreover, the Lang 3 package includes a great class, Validate, which > does > >> things right and now I can ask, why the hell is that not used throughout > >> the entire library? > >> > >> +1 to this. We should update all of lang to use Validate once we've > nailed > >> this issue. > >> > >> Duncan > >> > >>> > >>> > >>>>> However according to Apache Commons Lang Developer Guide, these > methods > >> are > >>>>> all correct. This guide says that "When throwing an exception to > >> indicate a > >>>>> bad argument, always try to throw IllegalArgumentException, even if > the > >>>>> argument was null. Do not throw NullPointerException.". > >>> > >>> > >>> Correct to the dev guide only -- not Java. > >>> > >>> > >>>> Since [lang] is currently designed this way, I'd rather deal with this > >>>> issue for 4.0. We can then revisit our initial decision to only throw > >> IAE > >>>> an maybe align it to what the JDK now does. If you want to file an > >> issue, > >>>> my opinion is, that it should be fix version 4.0. Changing the > >> exceptions > >>>> that are thrown now may break clients (although I think there are very > >> few > >>>> use cases where one should catch IAE or NPE). > >>> > >>> > >>> 4.0 has to use Validate throughout the entire package. NPE and IAE > >> indicate a programming error in the client not adhering to the contract > >> depicted by the Javadocs, so it is the client's problem to deal with > them. > >> With proper programming, you should not have to catch those exception at > >> all. > >>> > >>> > >>>>> This mail was sent in order to discuss around and make decisions to > >> solve > >>>>> this dilemma where the Java official specification says X and the > >> Apache > >>>>> official specification says Y. > >>>>> > >>>> > >>>> Can you please provide a lnk to the official specification you're > >> refering > >>>> to? ;-) > >>> > >>> > >>> Read Effective Java on exceptions. Thiago provided a URL in the JIRA > >> issue. > >>> > >>> Further good resources: > >>> > >>> 1. > >> > >> > http://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html > >>> 2. > >> > http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html: > >> "One case where it is common practice to throw a RuntimeException is > when > >> the user calls a method incorrectly. For example, a method can check if > one > >> of its arguments is incorrectly null. If an argument is null, the method > >> might throw a NullPointerException, which is an unchecked exception." > >>> > >>> Michael > >>> > >>> > >>> > >>> --------------------------------------------------------------------- > >>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > >>> For additional commands, e-mail: dev-help@commons.apache.org > >>> > >> > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org > For additional commands, e-mail: dev-help@commons.apache.org > > -- E-Mail: garydgregory@gmail.com | ggregory@apache.org Java Persistence with Hibernate, Second Edition JUnit in Action, Second Edition Spring Batch in Action Blog: http://garygregory.wordpress.com Home: http://garygregory.com/ Tweet! http://twitter.com/GaryGregory --001a11c33b0226f32b04f9499b5c--