You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Caused by: java.lang.NullPointerException
at com.hankcs.hanlp.corpus.io.ByteArrayOtherStream.ensureAvailableBytes(ByteArrayOtherStream.java:72)
at com.hankcs.hanlp.corpus.io.ByteArrayStream.nextInt(ByteArrayStream.java:56)
at com.hankcs.hanlp.collection.trie.DoubleArrayTrie.load(DoubleArrayTrie.java:531)
at com.hankcs.hanlp.collection.trie.DoubleArrayTrie.load(DoubleArrayTrie.java:516)
at com.hankcs.hanlp.dictionary.common.CommonDictionary.loadDat(CommonDictionary.java:90)
at com.hankcs.hanlp.dictionary.common.CommonDictionary.load(CommonDictionary.java:44)
at com.hankcs.hanlp.dictionary.nr.PersonDictionary.(PersonDictionary.java:57)
经过调试, 发现是由于resin对InputStream的实现is.available()每次最多读取8192个字节, 而不是将所有的数据都读取. 程序第一次在读取8192字节, 没有读取完整数据的情况下, 将InputStream流错误关闭, 第二次读取时报上述错误
if (readBytes == availableBytes)
{
is.close();
is = null;
}
下面是InputStream available 的文档
/**
* Returns an estimate of the number of bytes that can be read (or
* skipped over) from this input stream without blocking by the next
* invocation of a method for this input stream. The next invocation
* might be the same thread or another thread. A single read or skip of this
* many bytes will not block, but may read or skip fewer bytes.
*
* 这里说明了可能不会返回所有字节*
***
Note that while some implementations of {@code InputStream} will return
* the total number of bytes in the stream, many will not. It is
* never correct to use the return value of this method to allocate
* a buffer intended to hold all data in this stream.**
*
*
A subclass' implementation of this method may choose to throw an
* {@link IOException} if this input stream has been closed by
* invoking the {@link #close()} method.
*
*
The {@code available} method for class {@code InputStream} always
* returns {@code 0}.
*
*
This method should be overridden by subclasses.
*
* @return an estimate of the number of bytes that can be read (or skipped
* over) from this input stream without blocking or {@code 0} when
* it reaches the end of the input stream.
* @exception IOException if an I/O error occurs.
*/
建议代码修改:
if(is.available()==0)
{
is.close();
is = null;
}
期望输出
实际输出
其他信息
The text was updated successfully, but these errors were encountered:
注意事项
请确认下列注意事项:
版本号
当前最新版本号是:portable-1.3.3
我使用的版本是:portable-1.3.2
我的问题
在resin下部署HanLP 加载词典文件时, 出现空指针异常
Caused by: java.lang.NullPointerException
at com.hankcs.hanlp.corpus.io.ByteArrayOtherStream.ensureAvailableBytes(ByteArrayOtherStream.java:72)
at com.hankcs.hanlp.corpus.io.ByteArrayStream.nextInt(ByteArrayStream.java:56)
at com.hankcs.hanlp.collection.trie.DoubleArrayTrie.load(DoubleArrayTrie.java:531)
at com.hankcs.hanlp.collection.trie.DoubleArrayTrie.load(DoubleArrayTrie.java:516)
at com.hankcs.hanlp.dictionary.common.CommonDictionary.loadDat(CommonDictionary.java:90)
at com.hankcs.hanlp.dictionary.common.CommonDictionary.load(CommonDictionary.java:44)
at com.hankcs.hanlp.dictionary.nr.PersonDictionary.(PersonDictionary.java:57)
复现问题
每次都能复现
步骤
在resin环境下, 调用如下代码, 会产生异常
List<com.hankcs.hanlp.seg.common.Term> segment = HanLP.segment(episodeName);
触发代码
com.hankcs.hanlp.corpus.io.ByteArrayOtherStream.ensureAvailableBytes(ByteArrayOtherStream.java:72)
经过调试, 发现是由于resin对InputStream的实现is.available()每次最多读取8192个字节, 而不是将所有的数据都读取. 程序第一次在读取8192字节, 没有读取完整数据的情况下, 将InputStream流错误关闭, 第二次读取时报上述错误
if (readBytes == availableBytes)
{
is.close();
is = null;
}
下面是InputStream available 的文档
/**
* Returns an estimate of the number of bytes that can be read (or
* skipped over) from this input stream without blocking by the next
* invocation of a method for this input stream. The next invocation
* might be the same thread or another thread. A single read or skip of this
* many bytes will not block, but may read or skip fewer bytes.
*
* 这里说明了可能不会返回所有字节*
***
Note that while some implementations of {@code InputStream} will return
* the total number of bytes in the stream, many will not. It is
* never correct to use the return value of this method to allocate
* a buffer intended to hold all data in this stream.**
*
*
A subclass' implementation of this method may choose to throw an
* {@link IOException} if this input stream has been closed by
* invoking the {@link #close()} method.
*
*
The {@code available} method for class {@code InputStream} always
* returns {@code 0}.
*
*
This method should be overridden by subclasses.
*
* @return an estimate of the number of bytes that can be read (or skipped
* over) from this input stream without blocking or {@code 0} when
* it reaches the end of the input stream.
* @exception IOException if an I/O error occurs.
*/
建议代码修改:
if(is.available()==0)
{
is.close();
is = null;
}
期望输出
实际输出
其他信息
The text was updated successfully, but these errors were encountered: