Issue Details (XML | Word | Printable)

Key: LUCENE-1163
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Michael McCandless
Reporter: Thomas Peuss
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Lucene - Java

CharArraySet.contains(char[] text, int off, int len) does not work

Created: 05/Feb/08 01:18 PM   Updated: 11/Oct/08 12:49 PM
Return to search
Component/s: None
Affects Version/s: 2.3
Fix Version/s: 2.4

Time Tracking:
Not Specified

File Attachments:
  Size
Java Source File Licensed for inclusion in ASF works CharArraySetShowBug.java 2008-02-05 01:20 PM Thomas Peuss 0.6 kB
Text File Licensed for inclusion in ASF works LUCENE-1163.patch 2008-02-05 01:44 PM Michael McCandless 3 kB

Lucene Fields: New
Resolution Date: 05/Feb/08 02:04 PM


 Description  « Hide
I try to use the CharArraySet for a filter I am writing. I heavily use char-arrays in my code to speed up things. I stumbled upon a bug in CharArraySet while doing that.

The method public boolean contains(char[] text, int off, int len) seems not to work.

When I do

if (set.contains(buffer,offset,length) {
  ...
}

my code fails.

But when I do

if (set.contains(new String(buffer,offset,length)) {
   ...
}

everything works as expected.

Both variants should behave the same. I attach a small piece of code to show the problem.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Thomas Peuss added a comment - 05/Feb/08 01:20 PM
A simple piece of code that shows the problem.

Thomas Peuss made changes - 05/Feb/08 01:20 PM
Field Original Value New Value
Attachment CharArraySetShowBug.java [ 12374771 ]
Michael McCandless made changes - 05/Feb/08 01:38 PM
Assignee Michael McCandless [ mikemccand ]
Michael McCandless added a comment - 05/Feb/08 01:44 PM
Indeed it's really a bug – thank you for finding this & reporting it Thomas!

We were ignoring the offset when computing the hash code internally.

Lucene always passes '0' for this offset (only used in StopFilter currently) so it wasn't hitting any existing Lucene test cases.

I turned your example into a test case in the attached patch. I will commit shortly.


Michael McCandless made changes - 05/Feb/08 01:44 PM
Attachment LUCENE-1163.patch [ 12374772 ]
Thomas Peuss added a comment - 05/Feb/08 01:51 PM
Thanks for the quick response. I can confirm that the patch fixes the problem.

Repository Revision Date User Message
ASF #618652 Tue Feb 05 14:02:32 UTC 2008 mikemccand LUCENE-1163: get CharArraySet.contains(char[], int offset, int length) to actually pay attention to offset
Files Changed
MODIFY /lucene/java/trunk/src/test/org/apache/lucene/analysis/TestCharArraySet.java
MODIFY /lucene/java/trunk/CHANGES.txt
MODIFY /lucene/java/trunk/src/java/org/apache/lucene/analysis/CharArraySet.java

Michael McCandless added a comment - 05/Feb/08 02:04 PM
Super, thanks Thomas! I just committed this.

Michael McCandless made changes - 05/Feb/08 02:04 PM
Resolution Fixed [ 1 ]
Fix Version/s 2.4 [ 12312681 ]
Status Open [ 1 ] Resolved [ 5 ]
Michael McCandless added a comment - 12/Feb/08 11:02 AM
I'll port this one to 2.3.1 as well.

Repository Revision Date User Message
ASF #620765 Tue Feb 12 11:24:14 UTC 2008 mikemccand LUCENE-1163 (backport to 2.3): fixed bug in CharArraySet.contains that was ignoring the 'offset' argument
Files Changed
MODIFY /lucene/java/branches/lucene_2_3/src/java/org/apache/lucene/analysis/CharArraySet.java
MODIFY /lucene/java/branches/lucene_2_3/src/test/org/apache/lucene/analysis/TestCharArraySet.java
MODIFY /lucene/java/branches/lucene_2_3/CHANGES.txt

Michael McCandless added a comment - 12/Feb/08 11:24 AM
Backported to 2.3

Michael McCandless made changes - 11/Oct/08 12:49 PM
Status Resolved [ 5 ] Closed [ 6 ]