Add null check in InternalSearchHit#sourceRef to prevent NPE (#21431)
Add null check in InternalSearchHit#sourceRef to prevent NPE Closes #19279
This commit is contained in:
parent
4b94eb5cb8
commit
27a7b30349
|
@ -200,6 +200,10 @@ public class InternalSearchHit implements SearchHit {
|
|||
*/
|
||||
@Override
|
||||
public BytesReference sourceRef() {
|
||||
if (this.source == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
this.source = CompressorFactory.uncompressIfNeeded(this.source);
|
||||
return this.source;
|
||||
|
|
|
@ -76,4 +76,15 @@ public class InternalSearchHitTests extends ESTestCase {
|
|||
assertThat(results.getAt(1).shard(), equalTo(target));
|
||||
}
|
||||
|
||||
public void testNullSource() throws Exception {
|
||||
InternalSearchHit searchHit = new InternalSearchHit(0, "_id", new Text("_type"), null);
|
||||
|
||||
assertThat(searchHit.source(), nullValue());
|
||||
assertThat(searchHit.sourceRef(), nullValue());
|
||||
assertThat(searchHit.sourceAsMap(), nullValue());
|
||||
assertThat(searchHit.sourceAsString(), nullValue());
|
||||
assertThat(searchHit.getSource(), nullValue());
|
||||
assertThat(searchHit.getSourceRef(), nullValue());
|
||||
assertThat(searchHit.getSourceAsString(), nullValue());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue