lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <>
Subject RE: Lucene 2.9-RC2 : Bug in equals() of TermAttributeImpl
Date Tue, 08 Sep 2009 19:46:41 GMT
You are right, I will fix it.


The simpliest is to check if (termlength!=o.thermLength) before the
for-loop. The code is then equals to (I think this was a
copy'n'paste bug).


Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen


From: Daniel Shane [mailto:shaned@LEXUM.UMontreal.CA] 
Sent: Tuesday, September 08, 2009 9:32 PM
Subject: Lucene 2.9-RC2 : Bug in equals() of TermAttributeImpl


If you look at the code from equals(), I think it misses this check :


since it does not check if the termLength() are different.

Here is an example of a fix, it may not be optimal, but I think checking
size as the first thing is better than checking size after looping.

public boolean equals(Object other) {
    if (other == this) {
      return true;
    //Check for size also
    if (termLength() != ((TermAttributeImpl)other).termLength()) {
      return false;

    if (other instanceof TermAttribute) {
      TermAttributeImpl o = ((TermAttributeImpl) other);
      for(int i=0;i<termLength;i++) {
        if (termBuffer[i] != o.termBuffer[i]) {
          return false;
      return true;
    return false;

View raw message