You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by Yonik Seeley <ys...@gmail.com> on 2009/05/22 16:16:48 UTC
Re: svn commit: r777525 - /lucene/java/trunk/src/java/org/apache/lucene/util/AttributeSource.java
Why do stuff like this? Null params are almost never valid unless
documented... I dislike cluttering up code with validity checks,
slightly penalizing users who use the APIs correctly. I recognize
that I may be in the minority though.
But in this specific instance, the caller will get an immediate NPE if
they pass a null anyway.
-Yonik
http://www.lucidimagination.com
> public AttributeSource(AttributeSource input) {
> + if (input == null) {
> + throw new IllegalArgumentException("input AttributeSource must not be null");
> + }
> this.attributes = input.attributes;
> }
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org
Re: svn commit: r777525 - /lucene/java/trunk/src/java/org/apache/lucene/util/AttributeSource.java
Posted by Michael McCandless <lu...@mikemccandless.com>.
In general I agree, but in this case I think the check is warranted
because it used to be "fine" (in 2.4) to pass null -- nothing bad
would happen.
But as of the new TokenStream API, you'll suddenly hit an NPE, so I
think we should throw an informed exception so it's clear to users
what used to be accepted is in fact now explicitly disallowed.
Mike
On Fri, May 22, 2009 at 10:16 AM, Yonik Seeley <ys...@gmail.com> wrote:
> Why do stuff like this? Null params are almost never valid unless
> documented... I dislike cluttering up code with validity checks,
> slightly penalizing users who use the APIs correctly. I recognize
> that I may be in the minority though.
>
> But in this specific instance, the caller will get an immediate NPE if
> they pass a null anyway.
>
> -Yonik
> http://www.lucidimagination.com
>
>> public AttributeSource(AttributeSource input) {
>> + if (input == null) {
>> + throw new IllegalArgumentException("input AttributeSource must not be null");
>> + }
>> this.attributes = input.attributes;
>> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-dev-help@lucene.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org