You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ch...@apache.org on 2026/07/07 16:20:57 UTC
(lucene) branch branch_10x updated: Fix inconsistent null handling between array and single object version RAM estimation (#16296)
This is an automated email from the ASF dual-hosted git repository.
ChrisHegarty pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/branch_10x by this push:
new 4da9e3ed025 Fix inconsistent null handling between array and single object version RAM estimation (#16296)
4da9e3ed025 is described below
commit 4da9e3ed0251c6c50c0aeba2d6b0c16c0bd7309c
Author: Tim Grein <gr...@gmail.com>
AuthorDate: Tue Jul 7 18:09:19 2026 +0200
Fix inconsistent null handling between array and single object version RAM estimation (#16296)
When checking an array of Accountable there's an explicit null check avoiding NPEs, which would happen, when calling accountable.ramBytesUsed().
For the single object version sizeOf(Accountable accountable) this is not the case, therefore aligning the implementations.
---
lucene/CHANGES.txt | 3 +++
.../src/java/org/apache/lucene/util/RamUsageEstimator.java | 5 ++++-
.../test/org/apache/lucene/util/TestRamUsageEstimator.java | 12 ++++++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index c889b107b27..3fa9a445288 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -61,6 +61,9 @@ Bug Fixes
to the wrapped NumericDocValues, enabling optimized range evaluation for
single-valued sorted numeric fields. (Costin Leau)
+* GITHUB#16296: Fix missing null check in RamUsageEstimator.sizeOf(Accountable)
+ to be consistent with sizeOf(String) and sizeOf(Accountable[]). (Tim Grein)
+
Other
---------------------
* GITHUB#16266: Remove deprecated search(Query, Collector) calls in QueryUtils by replacing
diff --git a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
index e922c00064f..2710b0f4e23 100644
--- a/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
+++ b/lucene/core/src/java/org/apache/lucene/util/RamUsageEstimator.java
@@ -442,9 +442,12 @@ public final class RamUsageEstimator {
/**
* Returns the size in bytes of the {@link Accountable} object, using its {@link
- * Accountable#ramBytesUsed()} method.
+ * Accountable#ramBytesUsed()} method. Returns 0, if the {@link Accountable} object is null.
*/
public static long sizeOf(Accountable accountable) {
+ if (accountable == null) {
+ return 0;
+ }
return accountable.ramBytesUsed();
}
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
index 8e0bd13507e..5ffb7e9c3e0 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestRamUsageEstimator.java
@@ -150,6 +150,11 @@ public class TestRamUsageEstimator extends LuceneTestCase {
assertEquals((double) actual, (double) estimated, (double) actual * errorFactor);
}
+ public void testAccountable() {
+ assertEquals(0L, RamUsageEstimator.sizeOf((Accountable) null));
+ assertEquals(1L, RamUsageEstimator.sizeOf(new DummyAccountable()));
+ }
+
public void testCollection() {
List<Object> list = new ArrayList<>();
list.add(1234L);
@@ -252,4 +257,11 @@ public class TestRamUsageEstimator extends LuceneTestCase {
private static class HolderSubclass2 extends Holder {
// empty, only inherits all fields -> size should be identical to superclass
}
+
+ private static class DummyAccountable implements Accountable {
+ @Override
+ public long ramBytesUsed() {
+ return 1L;
+ }
+ }
}