You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by be...@apache.org on 2024/06/11 14:13:21 UTC

(lucene) branch branch_9_11 updated: Adjust assertion check to not throw an NPE (#13479)

This is an automated email from the ASF dual-hosted git repository.

benwtrent pushed a commit to branch branch_9_11
in repository https://gitbox.apache.org/repos/asf/lucene.git


The following commit(s) were added to refs/heads/branch_9_11 by this push:
     new 00a3950580d Adjust assertion check to not throw an NPE (#13479)
00a3950580d is described below

commit 00a3950580d5fbab27d8fbf8626c2ed7f28b64ff
Author: Benjamin Trent <be...@gmail.com>
AuthorDate: Tue Jun 11 09:48:21 2024 -0400

    Adjust assertion check to not throw an NPE (#13479)
---
 .../src/java/org/apache/lucene/index/SortingCodecReader.java | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

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 2e7fbf1b410..e9f959f34b8 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