You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2013/10/19 22:07:15 UTC
svn commit: r1533815 -
/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/HanjaUtils.java
Author: uschindler
Date: Sat Oct 19 20:07:15 2013
New Revision: 1533815
URL: http://svn.apache.org/r1533815
Log:
LUCENE-4956: Fix error handling in HanjaUtil to prevent NPE on broken classpath
Modified:
lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/HanjaUtils.java
Modified: lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/HanjaUtils.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/HanjaUtils.java?rev=1533815&r1=1533814&r2=1533815&view=diff
==============================================================================
--- lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/HanjaUtils.java (original)
+++ lucene/dev/branches/lucene4956/lucene/analysis/arirang/src/java/org/apache/lucene/analysis/ko/utils/HanjaUtils.java Sat Oct 19 20:07:15 2013
@@ -17,6 +17,8 @@ package org.apache.lucene.analysis.ko.ut
* limitations under the License.
*/
+import java.io.BufferedInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -37,9 +39,13 @@ public class HanjaUtils {
InputStream datStream = null, idxStream = null;
try {
datStream = DictionaryResources.class.getResourceAsStream(DictionaryResources.FILE_HANJA_DAT);
+ if (datStream == null)
+ throw new FileNotFoundException(DictionaryResources.FILE_HANJA_DAT);
idxStream = DictionaryResources.class.getResourceAsStream(DictionaryResources.FILE_HANJA_IDX);
- DataInput dat = new InputStreamDataInput(datStream);
- DataInput idx = new InputStreamDataInput(idxStream);
+ if (idxStream == null)
+ throw new FileNotFoundException(DictionaryResources.FILE_HANJA_IDX);
+ DataInput dat = new InputStreamDataInput(new BufferedInputStream(datStream));
+ DataInput idx = new InputStreamDataInput(new BufferedInputStream(idxStream));
CodecUtil.checkHeader(dat, DictionaryResources.FILE_HANJA_DAT, DictionaryResources.DATA_VERSION, DictionaryResources.DATA_VERSION);
CodecUtil.checkHeader(idx, DictionaryResources.FILE_HANJA_IDX, DictionaryResources.DATA_VERSION, DictionaryResources.DATA_VERSION);
data = new char[dat.readVInt()];
@@ -49,7 +55,7 @@ public class HanjaUtils {
}
index = new MonotonicBlockPackedReader(idx, idx.readVInt(), idx.readVInt(), idx.readVInt(), false);
} catch (IOException ioe) {
- throw new Error(ioe);
+ throw new Error("Cannot load resource", ioe);
} finally {
IOUtils.closeWhileHandlingException(datStream, idxStream);
}