Skip to content

Apache Lucene open-source search software

Adjust assertion check to not throw an NPE (#13479)

Benjamin Trentcfdc747cdea6
diff --git a/lucene/core/src/java/org/apache/lucene/index/SortingCodecReader.java b/lucene/core/src/java/org/apache/lucene/index/SortingCodecReader.java
index 4d1cb4c8cdb..67c76227385 100644
--- a/lucene/core/src/java/org/apache/lucene/index/SortingCodecReader.java
+++ b/lucene/core/src/java/org/apache/lucene/index/SortingCodecReader.java
@@ -736,10 +736,14 @@ public final class SortingCodecReader extends FilterCodecReader {
if (timesCached > 1) {
assert norms == false : "[" + field + "] norms must not be cached twice";
boolean isSortField = false;
- for (SortField sf : metaData.getSort().getSort()) {
- if (field.equals(sf.getField())) {
- isSortField = true;
- break;
+ // For things that aren't sort fields, it's possible for sort to be null here
+ // In the event that we accidentally cache twice, its better not to throw an NPE
+ if (metaData.getSort() != null) {
+ for (SortField sf : metaData.getSort().getSort()) {
+ if (field.equals(sf.getField())) {
+ isSortField = true;
+ break;
+ }
}
}
assert timesCached == 2