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/12/23 22:03:56 UTC

[GitHub] [lucene] ErikPelli opened a new pull request, #12034: Avoid possible NullPointerException in BlendedTermQuery

ErikPelli opened a new pull request, #12034:
URL: https://github.com/apache/lucene/pull/12034

   Avoid the call of get() method call in adjustFrequencies if the leaves List object returned by the context is null. 
   Actually the cycle is executed 1 time if it's null and this will cause a NullPointerException in leaves.get(i).
   Instead, we can avoid entirely the cycle if it's null since there isn't any information to iterate over and proceed with the function.


-- 
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


[GitHub] [lucene] zhaih merged pull request #12034: Remove null check in IndexReaderContext#leaves() usages

Posted by GitBox <gi...@apache.org>.
zhaih merged PR #12034:
URL: https://github.com/apache/lucene/pull/12034


-- 
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


[GitHub] [lucene] ErikPelli commented on a diff in pull request #12034: Remove null check in IndexReaderContext#leaves() usages

Posted by GitBox <gi...@apache.org>.
ErikPelli commented on code in PR #12034:
URL: https://github.com/apache/lucene/pull/12034#discussion_r1061673383


##########
lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java:
##########
@@ -314,19 +314,15 @@ private static TermStates adjustFrequencies(
       IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf)
       throws IOException {
     List<LeafReaderContext> leaves = readerContext.leaves();
-    final int len;
-    if (leaves == null) {
-      len = 1;
-    } else {
-      len = leaves.size();
-    }
     TermStates newCtx = new TermStates(readerContext);
-    for (int i = 0; i < len; ++i) {
-      TermState termState = ctx.get(leaves.get(i));
-      if (termState == null) {
-        continue;
+    if (leaves != null) {

Review Comment:
   Should I still add an entry in the CHANGES.txt file after this change?



-- 
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


[GitHub] [lucene] ErikPelli commented on a diff in pull request #12034: Avoid possible NullPointerException in BlendedTermQuery

Posted by GitBox <gi...@apache.org>.
ErikPelli commented on code in PR #12034:
URL: https://github.com/apache/lucene/pull/12034#discussion_r1061649853


##########
lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java:
##########
@@ -314,19 +314,15 @@ private static TermStates adjustFrequencies(
       IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf)
       throws IOException {
     List<LeafReaderContext> leaves = readerContext.leaves();
-    final int len;
-    if (leaves == null) {
-      len = 1;
-    } else {
-      len = leaves.size();
-    }
     TermStates newCtx = new TermStates(readerContext);
-    for (int i = 0; i < len; ++i) {
-      TermState termState = ctx.get(leaves.get(i));
-      if (termState == null) {
-        continue;
+    if (leaves != null) {

Review Comment:
   Ok, I missed that. In fact `IndexReaderContext` is an abstract class and the classes that extend it (`CompositeReaderContext` and `LeafReaderContext`) return a valid List or an exception. 
   So modify the doc is totaly fine, but it's needed also to remove the null check of result of `IndexReaderContext#leaves()` method call, because it won't ever happen.
   



-- 
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


[GitHub] [lucene] ErikPelli commented on a diff in pull request #12034: Remove null check in IndexReaderContext#leaves() usages

Posted by GitBox <gi...@apache.org>.
ErikPelli commented on code in PR #12034:
URL: https://github.com/apache/lucene/pull/12034#discussion_r1063816707


##########
lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java:
##########
@@ -314,19 +314,15 @@ private static TermStates adjustFrequencies(
       IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf)
       throws IOException {
     List<LeafReaderContext> leaves = readerContext.leaves();
-    final int len;
-    if (leaves == null) {
-      len = 1;
-    } else {
-      len = leaves.size();
-    }
     TermStates newCtx = new TermStates(readerContext);
-    for (int i = 0; i < len; ++i) {
-      TermState termState = ctx.get(leaves.get(i));
-      if (termState == null) {
-        continue;
+    if (leaves != null) {

Review Comment:
   Added it and squashed all the commits



-- 
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


[GitHub] [lucene] zhaih commented on a diff in pull request #12034: Remove null check in IndexReaderContext#leaves() usages

Posted by GitBox <gi...@apache.org>.
zhaih commented on code in PR #12034:
URL: https://github.com/apache/lucene/pull/12034#discussion_r1063684215


##########
lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java:
##########
@@ -314,19 +314,15 @@ private static TermStates adjustFrequencies(
       IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf)
       throws IOException {
     List<LeafReaderContext> leaves = readerContext.leaves();
-    final int len;
-    if (leaves == null) {
-      len = 1;
-    } else {
-      len = leaves.size();
-    }
     TermStates newCtx = new TermStates(readerContext);
-    for (int i = 0; i < len; ++i) {
-      TermState termState = ctx.get(leaves.get(i));
-      if (termState == null) {
-        continue;
+    if (leaves != null) {

Review Comment:
   Thanks for changing it, I think it is better to leave a CHNAGES.txt entry anyway!



-- 
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


[GitHub] [lucene] zhaih commented on a diff in pull request #12034: Avoid possible NullPointerException in BlendedTermQuery

Posted by GitBox <gi...@apache.org>.
zhaih commented on code in PR #12034:
URL: https://github.com/apache/lucene/pull/12034#discussion_r1060863978


##########
lucene/core/src/java/org/apache/lucene/search/BlendedTermQuery.java:
##########
@@ -314,19 +314,15 @@ private static TermStates adjustFrequencies(
       IndexReaderContext readerContext, TermStates ctx, int artificialDf, long artificialTtf)
       throws IOException {
     List<LeafReaderContext> leaves = readerContext.leaves();
-    final int len;
-    if (leaves == null) {
-      len = 1;
-    } else {
-      len = leaves.size();
-    }
     TermStates newCtx = new TermStates(readerContext);
-    for (int i = 0; i < len; ++i) {
-      TermState termState = ctx.get(leaves.get(i));
-      if (termState == null) {
-        continue;
+    if (leaves != null) {

Review Comment:
   I checked the implementations of the `IndexReaderContext#leaves()` method and seems it will never return `null`.
   
   So we probably even don't need this check here, instead could you help add the doc in the `IndexReaderContext#leaves()` method saying it should never return null?



-- 
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