[ 
https://issues.apache.org/jira/browse/SOLR-7017?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15172497#comment-15172497
 ] 

David Smiley commented on SOLR-7017:
------------------------------------

I've spent a fair amount of time recently working on this; there are *many* 
call sites to getParams and some of those gets simpler or are the same but need 
to change to check length > 0.  Just to review, the goals of a change here are:
* If the code just needs to loop over the entries, then it can just do so java5 
foreach loop (or otherwise) without a null check (avoid extra branch/indent & 2 
lines of code).
** Reduce bugs due to forgetting to check for null.  In some spots I found it 
could have NPE'ed due to parameters expected but not found; at least I thought 
so with a cursory look in some spots.
* if the code needs to ensure there are >0 entries then it just needs one 
condition, not 2 because of the null & zero len case.
** Reduce bugs due to forgetting to check for both; only one is needed.

So basically, simpler code and fewer bugs.  Ease of compatibility with Java 8 
Streams API too.

But this is a change with an impact to existing code alright; I can better 
appreciate Yonik's point now.

Before I continue and post a big patch, does this sound alright or would 
another approach seem better -- add a getParamsNotNull() method perhaps? *If* 
we did that, perhaps further guarantee that getParams() never returns a 
zero-len array.  This would give a choice -- the consuming code can call one or 
the other and it wouldn't have to check for both null _and_ zero-len; it would 
pick one or the other if it needs to know if there's data.  If it doesn't need 
to know (just needs to loop) then it'd call the NotNull variation.  This would 
have a smaller impact on existing code, I think.  But it may not be bold enough 
:-)

> SolrParams.getParams should return 0-length array instead of null
> -----------------------------------------------------------------
>
>                 Key: SOLR-7017
>                 URL: https://issues.apache.org/jira/browse/SOLR-7017
>             Project: Solr
>          Issue Type: Improvement
>            Reporter: David Smiley
>            Priority: Minor
>             Fix For: master
>
>
> It's a PITA to have code all over Solr littered with null checks for the 
> response of SolrParams.getParams(String param).  Can't we just have it return 
> a constant 0-length String array?



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to