Apache Lucene open-source search software
LUCENE-2510: fix more factory arg bugs found by TestFactories
Robert Muird58041803c7b
diff --git a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.javaindex 561568cfa35..137eb8eb511 100644--- a/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java+++ b/lucene/analysis/common/src/test/org/apache/lucene/analysis/core/TestFactories.java@@ -39,6 +39,9 @@ import org.apache.lucene.analysis.util.TokenizerFactory;* we do our best to see if we can sanely initialize it with* no parameters and smoke test it, etc.*/+// TODO: move this, TestRandomChains, and TestAllAnalyzersHaveFactories+// to an integration test module that sucks in all analysis modules.+// currently the only way to do this is via eclipse etc (LUCENE-3974)public class TestFactories extends BaseTokenStreamTestCase {public void test() throws IOException {for (String tokenizer : TokenizerFactory.availableTokenizers()) {diff --git a/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapanesePartOfSpeechStopFilterFactory.java b/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapanesePartOfSpeechStopFilterFactory.javaindex d0f9950d7d2..236fbd015af 100644--- a/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapanesePartOfSpeechStopFilterFactory.java+++ b/lucene/analysis/kuromoji/src/java/org/apache/lucene/analysis/ja/JapanesePartOfSpeechStopFilterFactory.java@@ -45,12 +45,15 @@ public class JapanesePartOfSpeechStopFilterFactory extends TokenFilterFactory impublic void inform(ResourceLoader loader) {String stopTagFiles = args.get("tags");enablePositionIncrements = getBoolean("enablePositionIncrements", false);+ stopTags = null;try {CharArraySet cas = getWordSet(loader, stopTagFiles, false);- stopTags = new HashSet<String>();- for (Object element : cas) {- char chars[] = (char[]) element;- stopTags.add(new String(chars));+ if (cas != null) {+ stopTags = new HashSet<String>();+ for (Object element : cas) {+ char chars[] = (char[]) element;+ stopTags.add(new String(chars));+ }}} catch (IOException e) {throw new InitializationException("IOException thrown while loading tags", e);@@ -58,6 +61,7 @@ public class JapanesePartOfSpeechStopFilterFactory extends TokenFilterFactory im}public TokenStream create(TokenStream stream) {- return new JapanesePartOfSpeechStopFilter(enablePositionIncrements, stream, stopTags);+ // if stoptags is null, it means the file is empty+ return stopTags == null ? stream : new JapanesePartOfSpeechStopFilter(enablePositionIncrements, stream, stopTags);}}diff --git a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.javaindex e4a56e38df6..3adb65a4028 100644--- a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java+++ b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMAAnnotationsTokenizerFactory.java@@ -18,6 +18,7 @@ package org.apache.lucene.analysis.uima;*/import org.apache.lucene.analysis.Tokenizer;+import org.apache.lucene.analysis.util.InitializationException;import org.apache.lucene.analysis.util.TokenizerFactory;import org.apache.lucene.analysis.uima.UIMAAnnotationsTokenizer;@@ -37,6 +38,9 @@ public class UIMAAnnotationsTokenizerFactory extends TokenizerFactory {super.init(args);descriptorPath = args.get("descriptorPath");tokenType = args.get("tokenType");+ if (descriptorPath == null || tokenType == null) {+ throw new InitializationException("Both descriptorPath and tokenType are mandatory");+ }}@Overridediff --git a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.javaindex f67ffc1f484..57b51838ba9 100644--- a/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java+++ b/lucene/analysis/uima/src/java/org/apache/lucene/analysis/uima/UIMATypeAwareAnnotationsTokenizerFactory.java@@ -19,6 +19,7 @@ package org.apache.lucene.analysis.uima;import org.apache.lucene.analysis.Tokenizer;import org.apache.lucene.analysis.uima.UIMATypeAwareAnnotationsTokenizer;+import org.apache.lucene.analysis.util.InitializationException;import org.apache.lucene.analysis.util.TokenizerFactory;import java.io.Reader;@@ -39,6 +40,9 @@ public class UIMATypeAwareAnnotationsTokenizerFactory extends TokenizerFactory {descriptorPath = args.get("descriptorPath");tokenType = args.get("tokenType");featurePath = args.get("featurePath");+ if (descriptorPath == null || tokenType == null || featurePath == null) {+ throw new InitializationException("descriptorPath, tokenType, and featurePath are mandatory");+ }}@Override