diff --git a/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java b/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java index 313301e1345..7028a81808d 100644 --- a/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java +++ b/lucene/core/src/java/org/apache/lucene/util/hnsw/HnswUtil.java @@ -106,7 +106,9 @@ public class HnswUtil { } else { entryPoint = connectedNodes.nextSetBit(0); } - components.add(new Component(entryPoint, total)); + if (total > 0) { + components.add(new Component(entryPoint, total)); + } if (level == 0) { int nextClear = nextClearBit(connectedNodes, 0); while (nextClear != NO_MORE_DOCS) {