From f96b02af060feaa044b85224bfbfeeb548e8b1da Mon Sep 17 00:00:00 2001 From: Doron Cohen Date: Fri, 7 Dec 2012 11:31:53 +0000 Subject: [PATCH] LUCENE--4595: EnwikiContentSource thread safety NPE in 'forever' mode git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1418281 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 3 ++ .../byTask/feeds/EnwikiContentSource.java | 32 ++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index cd0d78a0b74..d6a7d92d3e7 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -219,6 +219,9 @@ Bug Fixes In addition, it wasn't possible to index a shape representing the entire globe. +* LUCENE--4595: EnwikiContentSource had a thread safety problem (NPE) in + 'forever' mode (Doron Cohen) + Optimizations * LUCENE-2221: oal.util.BitUtil was modified to use Long.bitCount and diff --git a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java index 4a0dde0920d..09745cbe88e 100644 --- a/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java +++ b/lucene/benchmark/src/java/org/apache/lucene/benchmark/byTask/feeds/EnwikiContentSource.java @@ -178,23 +178,25 @@ public class EnwikiContentSource extends ContentSource { reader.setErrorHandler(this); while(!stopped){ final InputStream localFileIS = is; - try { - // To work around a bug in XERCES (XERCESJ-1257), we assume the XML is always UTF8, so we simply provide reader. - CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder() - .onMalformedInput(CodingErrorAction.REPORT) - .onUnmappableCharacter(CodingErrorAction.REPORT); - reader.parse(new InputSource(new BufferedReader(new InputStreamReader(localFileIS, decoder)))); - } catch (IOException ioe) { - synchronized(EnwikiContentSource.this) { - if (localFileIS != is) { - // fileIS was closed on us, so, just fall through - } else - // Exception is real - throw ioe; + if (localFileIS != null) { // null means fileIS was closed on us + try { + // To work around a bug in XERCES (XERCESJ-1257), we assume the XML is always UTF8, so we simply provide reader. + CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder() + .onMalformedInput(CodingErrorAction.REPORT) + .onUnmappableCharacter(CodingErrorAction.REPORT); + reader.parse(new InputSource(new BufferedReader(new InputStreamReader(localFileIS, decoder)))); + } catch (IOException ioe) { + synchronized(EnwikiContentSource.this) { + if (localFileIS != is) { + // fileIS was closed on us, so, just fall through + } else + // Exception is real + throw ioe; + } } } synchronized(this) { - if (!forever) { + if (stopped || !forever) { nmde = new NoMoreDataException(); notify(); return; @@ -291,11 +293,11 @@ public class EnwikiContentSource extends ContentSource { @Override public void close() throws IOException { synchronized (EnwikiContentSource.this) { + parser.stop(); if (is != null) { is.close(); is = null; } - parser.stop(); } }