nonNull and similar methods [was Re: First round of java.util.Objects for code review (bug 6797535)] (original) (raw)
Kevin Bourrillion kevinb at google.com
Fri Oct 23 19:33:10 UTC 2009
- Previous message: nonNull and similar methods [was Re: First round of java.util.Objects for code review (bug 6797535)]
- Next message: First round of java.util.Objects for code review (bug 6797535)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Oct 14, 2009 at 3:38 AM, Stephen Colebourne <scolebourne at joda.org>wrote:
While I agree that the nonNull methods below are useful and should be in the
JDK, I question whether they should be on j.u.Objects.
I believe that there is a whole category of methods to pre-validate the arguments of a method, such as Commons Lang Validate, or Google Prevalidate.
[s/Prevalidate/Preconditions/]
I'm in complete agreement, of course. In Google, checkNotNull() is certainly the most popular of our Preconditions methods, but checkArgument() is fully half as popular, and checkState() half in turn (meaning it's still used thousands upon thousands of times). We also have similar methods to throw IndexOutOfBoundsExceptions when appropriate, which are not needed nearly as frequently, but are a real relief to use when you do need them (many JDK methods could make use of them, especially since Martin has just finished optimizing the heck out of them for our next RC (1.0-rc4)).
checkArgument() and checkState() don't let developers do anything they can't already do with if/throw, but I very strongly believe we have significantly more of our codebase doing proper precondition checking because of this small amount of paving we applied to that path.
Just some more input to consider.
http://commons.apache.org/lang/apidocs/org/apache/commons/lang/Validate.html http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/base/Preconditions.html
Kevin Bourrillion @ Google internal: http://go/javalibraries external: guava-libraries.googlecode.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20091023/362a275c/attachment.html>
- Previous message: nonNull and similar methods [was Re: First round of java.util.Objects for code review (bug 6797535)]
- Next message: First round of java.util.Objects for code review (bug 6797535)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]