lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Uwe Schindler" <...@thetaphi.de>
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 Token.java (I think this was a
copy'n'paste bug).

 

-----
Uwe Schindler
H.-H.-Meier-Allee 63, D-28213 Bremen
http://www.thetaphi.de
eMail: uwe@thetaphi.de

  _____  

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

 

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

"AX".equals("A");

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) {
      initTermBuffer();
      TermAttributeImpl o = ((TermAttributeImpl) other);
      o.initTermBuffer();
      
      for(int i=0;i<termLength;i++) {
        if (termBuffer[i] != o.termBuffer[i]) {
          return false;
        }
      }
      return true;
    }
    
    return false;
  } 


Mime
View raw message