You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/11/22 11:13:03 UTC

[GitHub] [lucene] jpountz commented on a diff in pull request #11950: Fix NPE in BinaryRangeFieldRangeQuery when field does not exist or is of wrong type

jpountz commented on code in PR #11950:
URL: https://github.com/apache/lucene/pull/11950#discussion_r1029197613


##########
lucene/core/src/java/org/apache/lucene/document/BinaryRangeFieldRangeQuery.java:
##########
@@ -91,7 +92,11 @@ public Query rewrite(IndexSearcher indexSearcher) throws IOException {
   }
 
   private BinaryRangeDocValues getValues(LeafReader reader, String field) throws IOException {
-    BinaryDocValues binaryDocValues = reader.getBinaryDocValues(field);
+    FieldInfo info = reader.getFieldInfos().fieldInfo(field);
+    if (info == null) {
+      return null;
+    }
+    BinaryDocValues binaryDocValues = DocValues.getBinary(reader, field);

Review Comment:
   I'm not sure I understand why we need to retrieve field infos, `getBinaryDocValues` already returns `null` when the field doesn't exist, so doing the following should be enough?
   
   ```
   BinaryDocValues binaryDocValues = reader.getBinaryDocValues(field);
   if (binaryDocValues == null) {
     return null;
   }
   return new BinaryRangeDocValues(binaryDocValues, numDims, numBytesPerDimension);
   ```



##########
lucene/CHANGES.txt:
##########
@@ -143,6 +143,9 @@ Bug Fixes
 
 * GITHUB#11907: Fix latent casting bugs in BKDWriter. (Ben Trent)
 
+* GITHUB#11950: Fix NPE in BinaryRangeFieldRangeQuery variants when the queried field doesn't exist
+  in a segment or is of the wrong type. (Greg Miller)

Review Comment:
   Is is true that there would be a NPE when the field is of the wrong type? I would have expected `CodecReader#getBinaryDocValues` to catch the problem?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@lucene.apache.org
For additional commands, e-mail: issues-help@lucene.apache.org