-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Description
Elasticsearch version: 2.1.1(2.x)
JVM version: 1.8.0_66-b17
OS version: Mac OS X 10.10.5
Description of the problem including expected versus actual behavior:
java.lang.NullPointerException will be thrown when converting search response to json if search hits without no source returned(just specify search field) and compress is enable, because the isCompressed method of LZFCompressor and DeflateCompressor will check the parameter 'bytes' is null or not before do uncompress operation.
Stacktrace can be referenced at log section.
Steps to reproduce:
- Use SearchRequestBuilder.addField() to add search result field before execute search operation and it will not return source of document for search response hits.
- Execute search operation.
- Get the reference SearchResponse and use com.alibaba.fastjson.JSON.toJSONString() to convert it into json string, you will got NPE
Provide logs (if relevant):
java.lang.NullPointerException: null
at org.elasticsearch.common.compress.lzf.LZFCompressor.isCompressed(LZFCompressor.java:54) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.common.compress.CompressorFactory.compressor(CompressorFactory.java:74) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.common.compress.CompressorFactory.uncompressIfNeeded(CompressorFactory.java:118) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.search.internal.InternalSearchHit.sourceRef(InternalSearchHit.java:200) ~[elasticsearch-2.1.1.jar:2.1.1]
at org.elasticsearch.search.internal.InternalSearchHit.getSourceRef(InternalSearchHit.java:219) ~[elasticsearch-2.1.1.jar:2.1.1]
at Serializer_17.write1(Unknown Source) ~[na:na]
at Serializer_17.write(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.ArraySerializer.write(ArraySerializer.java:64) ~[fastjson-1.2.8.jar:na]
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) ~[fastjson-1.2.8.jar:na]
at Serializer_16.write1(Unknown Source) ~[na:na]
at Serializer_16.write(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) ~[fastjson-1.2.8.jar:na]
at Serializer_14.write1(Unknown Source) ~[na:na]
at Serializer_14.write(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.JSONSerializer.writeWithFieldName(JSONSerializer.java:403) ~[fastjson-1.2.8.jar:na]
at Serializer_12.write1(Unknown Source) ~[na:na]
at Serializer_12.write(Unknown Source) ~[na:na]
at com.alibaba.fastjson.serializer.JSONSerializer.write(JSONSerializer.java:374) ~[fastjson-1.2.8.jar:na]
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:394) ~[fastjson-1.2.8.jar:na]
at com.alibaba.fastjson.JSON.toJSONString(JSON.java:382) ~[fastjson-1.2.8.jar:na]