[ 
http://issues.apache.org/jira/browse/LUCENE-650?page=comments#action_12428955 ] 
            
Doron Cohen commented on LUCENE-650:
------------------------------------

I reviewed this patch and think that it is valid.

This seems like a real bug:
 - In FieldSortedHitQueue, when no locale is specified, a comparator is based 
on getStringsIndex() - because the natural terms order can be used for 
comparison. 
- Notice that getStringsIndex() has a special care for docs with no values - 
their index is set to 0 (default index array initialization) and all terms are 
placed from index 1 and up. 
- But when a locale is specified, the natural terms cannot be used, and hence 
getStrings() is used (instead of getStringsIndex()). Here there is no special 
care for "no values", and hence the result strings array can contain nulls. 
- These null values are later passed to the  locale comparator, and e get wa 
NPE.
- The Javadocs for java.text.Collator do not specify behavior for null 
argument, so this can not be regarded as an issue of a certain JDK 
implementation - we should avoid passing null to the comparator.

I see two ways to solve this: 
- one is to assign "" (empty string) in the comparator for all the null values. 
But this would modify the semantics of the FieldCache, that stores this array 
of strings. It would be wrong to do so, and it would also take more time.
- the other way - that seems the right way - is that of this patch, which 
handles null values just before passing them to the collator compare method. 
(The 3 if statements added may have performance implications - I did not test 
performance.)

I ran the TestSort (from the patch) without applying the patch fix to 
FieldSortedHitQueue, and the test failed. After applying the fix to 
FieldSortedHitQueue the test passed.  All "ant test" tests pass as well.

- Doron

> NPE doing local sensitive sorting when sort field is missing
> ------------------------------------------------------------
>
>                 Key: LUCENE-650
>                 URL: http://issues.apache.org/jira/browse/LUCENE-650
>             Project: Lucene - Java
>          Issue Type: Bug
>          Components: Search
>    Affects Versions: 2.0.0
>            Reporter: Oliver Hutchison
>         Attachments: sortNpeFix.patch
>
>
> If you do a local sensitive sort against a field that is missing from some 
> documents in the index an NPE will get thrown.
> Attached is a patch which resolved the issue and updates the sort test case 
> to give coverage to this issue.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to