I fixed it! Thank you very much!!!

 

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

  _____  

From: Uwe Schindler [mailto:u...@thetaphi.de] 
Sent: Tuesday, September 08, 2009 9:47 PM
To: java-dev@lucene.apache.org
Subject: RE: Lucene 2.9-RC2 : Bug in equals() of TermAttributeImpl

 

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: u...@thetaphi.de

  _____  

From: Daniel Shane [mailto:sha...@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;
  } 

Reply via email to