You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by "tyronecai (via GitHub)" <gi...@apache.org> on 2026/02/12 03:58:39 UTC
[PR] Fix Potential NullPointException in BytesRefHash initialization [lucene]
tyronecai opened a new pull request, #15702:
URL: https://github.com/apache/lucene/pull/15702
### Description
<!--
If this is your first contribution to Lucene, please make sure you have reviewed the contribution guide.
https://github.com/apache/lucene/blob/main/CONTRIBUTING.md
-->
because of variable shadowing, an npe may produce here
```
final Counter bytesUsed = bytesStartArray.bytesUsed();
this.bytesUsed = bytesUsed == null ? Counter.newCounter() : bytesUsed;
bytesUsed.addAndGet(hashSize * (long) Integer.BYTES);
~~~~~~
```
ref: https://github.com/apache/lucene/issues/15701
--
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
Re: [PR] Fix Potential NullPointException in BytesRefHash initialization [lucene]
Posted by "mikemccand (via GitHub)" <gi...@apache.org>.
mikemccand commented on code in PR #15702:
URL: https://github.com/apache/lucene/pull/15702#discussion_r2799076987
##########
lucene/core/src/java/org/apache/lucene/util/BytesRefHash.java:
##########
@@ -138,7 +138,7 @@ public BytesRefHash(ByteBlockPool pool, int capacity, BytesStartArray bytesStart
bytesStart = bytesStartArray.init();
final Counter bytesUsed = bytesStartArray.bytesUsed();
this.bytesUsed = bytesUsed == null ? Counter.newCounter() : bytesUsed;
- bytesUsed.addAndGet(hashSize * (long) Integer.BYTES);
+ this.bytesUsed.addAndGet(hashSize * (long) Integer.BYTES);
Review Comment:
Whoa, nice catch, thank you @tyronecai and IntelliJ! I wonder if there is a low-false-positive (high signal to noise ratio) static checker we could turn on in Lucene's CI builds to catch this kind of lurking bug?
I think it indeed must be that all the `BytesStartArrays` used here have a non-null `bytesUsed`? In which case +1 to make it required not `null` (change to `assert`). This is technically a public API, but `@lucene.internal` (well, `BytesRefHash` is), so we are free to suddenly change API/requirement here.
--
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
Re: [PR] Fix Potential NullPointException in BytesRefHash initialization [lucene]
Posted by "tyronecai (via GitHub)" <gi...@apache.org>.
tyronecai commented on PR #15702:
URL: https://github.com/apache/lucene/pull/15702#issuecomment-3890326542
> I wonder why we never hit this NPE... maybe it's just not possible and we should remove the code entirely and replace it with an assertion that bytesUsed != null?
Is it necessary to assume that bytesStartArray.bytesUsed() never null ?
just a variable shadowing issue
--
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
Re: [PR] Fix Potential NullPointException in BytesRefHash initialization [lucene]
Posted by "dweiss (via GitHub)" <gi...@apache.org>.
dweiss merged PR #15702:
URL: https://github.com/apache/lucene/pull/15702
--
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
Re: [PR] Fix Potential NullPointException in BytesRefHash initialization [lucene]
Posted by "dweiss (via GitHub)" <gi...@apache.org>.
dweiss commented on PR #15702:
URL: https://github.com/apache/lucene/pull/15702#issuecomment-3901739948
Can you add an entry to CHANGES.txt under 10.5.0? I'll merge and backport.
--
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
Re: [PR] Fix Potential NullPointException in BytesRefHash initialization [lucene]
Posted by "tyronecai (via GitHub)" <gi...@apache.org>.
tyronecai commented on PR #15702:
URL: https://github.com/apache/lucene/pull/15702#issuecomment-3939917722
> Can you add an entry to CHANGES.txt under 10.5.0? I'll merge and backport.
Apologize for the late reply, I just returned from the Spring Festival holiday.
Thank @mikemccand , @dweiss both for your time.
--
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