Index: modules/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java =================================================================== --- modules/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java (revision 1244932) +++ modules/analysis/uima/src/test/org/apache/lucene/analysis/uima/UIMABaseAnalyzerTest.java (working copy) @@ -19,6 +19,7 @@ import org.apache.lucene.analysis.BaseTokenStreamTestCase; import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.Tokenizer; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.document.TextField; @@ -57,6 +58,32 @@ } @Test + public void testSetReaderAndClose() throws Exception { + StringReader input = new StringReader("the big brown fox jumped on the wood"); + Tokenizer t = new UIMAAnnotationsTokenizer("/uima/AggregateSentenceAE.xml", "org.apache.uima.TokenAnnotation", input); + assertTokenStreamContents(t, new String[]{"the", "big", "brown", "fox", "jumped", "on", "the", "wood"}); + t.close(); + try { + t.incrementToken(); + fail("should've been failed as reader is not set"); + } catch (AssertionError error) { + // ok + } + input = new StringReader("hi oh my"); + t = new UIMAAnnotationsTokenizer("/uima/TestAggregateSentenceAE.xml", "org.apache.lucene.uima.ts.TokenAnnotation", input); + assertTrue("should've been incremented ", t.incrementToken()); + t.close(); + try { + t.incrementToken(); + fail("should've been failed as reader is not set"); + } catch (AssertionError error) { + // ok + } + t.reset(new StringReader("hey what do you say")); + assertTrue("should've been incremented ", t.incrementToken()); + } + + @Test public void baseUIMAAnalyzerStreamTest() throws Exception { TokenStream ts = analyzer.tokenStream("text", new StringReader("the big brown fox jumped on the wood")); assertTokenStreamContents(ts, new String[]{"the", "big", "brown", "fox", "jumped", "on", "the", "wood"}); Index: modules/analysis/uima/src/java/org/apache/lucene/analysis/uima/BaseUIMATokenizer.java =================================================================== --- modules/analysis/uima/src/java/org/apache/lucene/analysis/uima/BaseUIMATokenizer.java (revision 1244932) +++ modules/analysis/uima/src/java/org/apache/lucene/analysis/uima/BaseUIMATokenizer.java (working copy) @@ -51,19 +51,20 @@ /** * analyzes the tokenizer input using the given analysis engine - * + *
* {@link #cas} will be filled with extracted metadata (UIMA annotations, feature structures) * * @throws AnalysisEngineProcessException * @throws IOException */ - protected void analyzeInput() throws AnalysisEngineProcessException,IOException { + protected void analyzeInput() throws AnalysisEngineProcessException, IOException { cas.reset(); cas.setDocumentText(toString(input)); ae.process(cas); } private String toString(Reader reader) throws IOException { + assert reader != null : "input has been closed, please reset it"; StringBuilder stringBuilder = new StringBuilder(); int ch; while ((ch = reader.read()) > -1) { @@ -82,6 +83,14 @@ public void end() throws IOException { iterator = null; } - - + + @Override + public void close() throws IOException { + super.close(); + // release UIMA resources + if (iterator != null) + iterator = null; + cas.release(); + ae.destroy(); + } } Index: modules/analysis/uima/build.xml =================================================================== --- modules/analysis/uima/build.xml (revision 1244932) +++ modules/analysis/uima/build.xml (working copy) @@ -26,7 +26,7 @@