lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shai Erera <>
Subject Bug in Token.copyTo?
Date Mon, 23 Nov 2009 11:19:10 GMT

I think that Token.copyTo is buggy. It checks if the AttributeImpl is
instanceof Token, and if so reinits. However if it's not, it casts
AttributeImpl to *ALL* of TermAttribute, OffsetAttribute,
PositionIncrementAttribute etc. and sets them w/ the proper values. However,
one can pass an AttributeImpl which is not Token, but one of its
implementing interfaces, such as TermAttribute, and then the code breaks w/
a ClassCastException.

There's nothing in the API which prevents me from passing a non-Token
instance, and more than that - it looks as if the code tries to optimize for
a Token instance, but does not handle properly other cases. I think the
'else' clause should include instanceof checks, because obviously I cannot
pass an instance that implements all of the interfaces and is not Token
(well I can, but what's the point, just use Token).

Here is a short example which reproduces:

      Token token = new Token("hello", 0, 5);
      TermAttributeImpl term = new TermAttributeImpl();



View raw message