Skip to content

Apache Lucene open-source search software

onlyUseNewAPI is a static, so non-instance variable. It is used only to initialize TokenStreams and can be changed after. Because of that the tests in incrementToken()/next()/next(Token) should not use it. It is enough to test for tokenWrapper==null to detect a onlyNewAPI TokenStream instance.

Uwe Schindlerc339c58f4ed4
diff --git a/src/java/org/apache/lucene/analysis/TokenStream.java b/src/java/org/apache/lucene/analysis/TokenStream.java
index 1a602381cfd..c8b56ac5f64 100644
--- a/src/java/org/apache/lucene/analysis/TokenStream.java
+++ b/src/java/org/apache/lucene/analysis/TokenStream.java
@@ -305,7 +305,7 @@ public abstract class TokenStream extends AttributeSource {
* 3.0.</b>
*/
public boolean incrementToken() throws IOException {
- assert !onlyUseNewAPI && tokenWrapper != null;
+ assert tokenWrapper != null;
final Token token;
if (supportedMethods.hasReusableNext) {
@@ -369,7 +369,7 @@ public abstract class TokenStream extends AttributeSource {
public Token next(final Token reusableToken) throws IOException {
assert reusableToken != null;
- if (onlyUseNewAPI)
+ if (tokenWrapper == null)
throw new UnsupportedOperationException("This TokenStream only supports the new Attributes API.");
if (supportedMethods.hasIncrementToken) {
@@ -393,7 +393,7 @@ public abstract class TokenStream extends AttributeSource {
* method with the new {@link AttributeSource} API.
*/
public Token next() throws IOException {
- if (onlyUseNewAPI)
+ if (tokenWrapper == null)
throw new UnsupportedOperationException("This TokenStream only supports the new Attributes API.");
if (supportedMethods.hasIncrementToken) {