Hi

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();

      token.copyTo(term);
      System.out.println(term);

Shai

Reply via email to