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
This commit is contained in:
Doron Cohen 2012-12-07 11:31:53 +00:00
parent 49593470e3
commit f96b02af06
2 changed files with 20 additions and 15 deletions

View File

@ -219,6 +219,9 @@ Bug Fixes
In addition, it wasn't possible to index a shape representing the entire In addition, it wasn't possible to index a shape representing the entire
globe. globe.
* LUCENE--4595: EnwikiContentSource had a thread safety problem (NPE) in
'forever' mode (Doron Cohen)
Optimizations Optimizations
* LUCENE-2221: oal.util.BitUtil was modified to use Long.bitCount and * LUCENE-2221: oal.util.BitUtil was modified to use Long.bitCount and

View File

@ -178,23 +178,25 @@ public class EnwikiContentSource extends ContentSource {
reader.setErrorHandler(this); reader.setErrorHandler(this);
while(!stopped){ while(!stopped){
final InputStream localFileIS = is; final InputStream localFileIS = is;
try { if (localFileIS != null) { // null means fileIS was closed on us
// To work around a bug in XERCES (XERCESJ-1257), we assume the XML is always UTF8, so we simply provide reader. try {
CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder() // To work around a bug in XERCES (XERCESJ-1257), we assume the XML is always UTF8, so we simply provide reader.
.onMalformedInput(CodingErrorAction.REPORT) CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()
.onUnmappableCharacter(CodingErrorAction.REPORT); .onMalformedInput(CodingErrorAction.REPORT)
reader.parse(new InputSource(new BufferedReader(new InputStreamReader(localFileIS, decoder)))); .onUnmappableCharacter(CodingErrorAction.REPORT);
} catch (IOException ioe) { reader.parse(new InputSource(new BufferedReader(new InputStreamReader(localFileIS, decoder))));
synchronized(EnwikiContentSource.this) { } catch (IOException ioe) {
if (localFileIS != is) { synchronized(EnwikiContentSource.this) {
// fileIS was closed on us, so, just fall through if (localFileIS != is) {
} else // fileIS was closed on us, so, just fall through
// Exception is real } else
throw ioe; // Exception is real
throw ioe;
}
} }
} }
synchronized(this) { synchronized(this) {
if (!forever) { if (stopped || !forever) {
nmde = new NoMoreDataException(); nmde = new NoMoreDataException();
notify(); notify();
return; return;
@ -291,11 +293,11 @@ public class EnwikiContentSource extends ContentSource {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
synchronized (EnwikiContentSource.this) { synchronized (EnwikiContentSource.this) {
parser.stop();
if (is != null) { if (is != null) {
is.close(); is.close();
is = null; is = null;
} }
parser.stop();
} }
} }