Apache Lucene open-source search software
LUCENE-3990: don't extend charfilter here, delegate all methods
Robert Muir776e1b4a983d
diff --git a/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.javanew file mode 100644index 00000000000..5cd5c65508b--- /dev/null+++ b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestBugInSomething.java@@ -0,0 +1,64 @@+package org.apache.lucene.analysis.core;++import java.io.Reader;++import org.apache.lucene.analysis.Analyzer;+import org.apache.lucene.analysis.BaseTokenStreamTestCase;+import org.apache.lucene.analysis.MockCharFilter;+import org.apache.lucene.analysis.MockTokenFilter;+import org.apache.lucene.analysis.MockTokenizer;+import org.apache.lucene.analysis.TokenFilter;+import org.apache.lucene.analysis.Tokenizer;+import org.apache.lucene.analysis.charfilter.MappingCharFilter;+import org.apache.lucene.analysis.charfilter.NormalizeCharMap;+import org.apache.lucene.analysis.commongrams.CommonGramsFilter;+import org.apache.lucene.analysis.util.CharArraySet;++/**+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++public class TestBugInSomething extends BaseTokenStreamTestCase {+ public void test() throws Exception {+ final CharArraySet cas = new CharArraySet(TEST_VERSION_CURRENT, 3, false);+ cas.add("jjp");+ cas.add("wlmwoknt");+ cas.add("tcgyreo");++ final NormalizeCharMap map = new NormalizeCharMap();+ map.add("mtqlpi", "");+ map.add("mwoknt", "jjp");+ map.add("tcgyreo", "zpfpajyws");+ map.add("", "eethksv");++ Analyzer a = new Analyzer() {+ @Override+ protected TokenStreamComponents createComponents(String fieldName, Reader reader) {+ Tokenizer t = new MockTokenizer(new TestRandomChains.CheckThatYouDidntReadAnythingReaderWrapper(reader), MockTokenFilter.ENGLISH_STOPSET, false, -65);+ TokenFilter f = new CommonGramsFilter(TEST_VERSION_CURRENT, t, cas);+ return new TokenStreamComponents(t, f);+ }++ @Override+ protected Reader initReader(Reader reader) {+ reader = new MockCharFilter(reader, 0);+ reader = new MappingCharFilter(map, reader);+ return reader;+ }+ };+ checkAnalysisConsistency(random(), a, false, "wmgddzunizdomqyj");+ }+}diff --git a/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.javaindex e1804868c95..fdd5aadb123 100644--- a/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java+++ b/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java@@ -756,44 +756,77 @@ public class TestRandomChains extends BaseTokenStreamTestCase {}}- static final class CheckThatYouDidntReadAnythingReaderWrapper extends CharFilter {- boolean readSomething = false;+ // wants charfilter to be a filterreader...+ // do *NOT* refactor me to be a charfilter: LUCENE-3990+ static class CheckThatYouDidntReadAnythingReaderWrapper extends CharStream {+ boolean readSomething;+ CharStream in;CheckThatYouDidntReadAnythingReaderWrapper(Reader in) {- super(CharReader.get(in));+ this.in = CharReader.get(in);+ }++ @Override+ public int correctOffset(int currentOff) {+ return in.correctOffset(currentOff);+ }++ @Override+ public void close() throws IOException {+ in.close();}@Overridepublic int read(char[] cbuf, int off, int len) throws IOException {readSomething = true;- return super.read(cbuf, off, len);+ return in.read(cbuf, off, len);}@Overridepublic int read() throws IOException {readSomething = true;- return super.read();+ return in.read();}@Overridepublic int read(CharBuffer target) throws IOException {readSomething = true;- return super.read(target);+ return in.read(target);+ }++ @Override+ public void mark(int readAheadLimit) throws IOException {+ in.mark(readAheadLimit);+ }++ @Override+ public boolean markSupported() {+ return in.markSupported();}@Overridepublic int read(char[] cbuf) throws IOException {readSomething = true;- return super.read(cbuf);+ return in.read(cbuf);+ }++ @Override+ public boolean ready() throws IOException {+ return in.ready();+ }++ @Override+ public void reset() throws IOException {+ in.reset();}@Overridepublic long skip(long n) throws IOException {readSomething = true;- return super.skip(n);+ return in.skip(n);}}-+static class TokenizerSpec {Tokenizer tokenizer;String toString;