From 568372fe45227bb173f47e4a00889425a38243c0 Mon Sep 17 00:00:00 2001 From: Michael Sokolov Date: Fri, 18 Oct 2024 15:40:09 -0400 Subject: [PATCH] fix initialization bug in SlowCompositeCodecReaderWrapper --- .../lucene/index/SlowCompositeCodecReaderWrapper.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java index 920da7dbb6e2..fa8dea050966 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java +++ b/lucene/core/src/java/org/apache/lucene/index/SlowCompositeCodecReaderWrapper.java @@ -887,6 +887,7 @@ public Floats vectors() { return new Floats() { int lastSubIndex = 0; Floats subValues; + // TODO: cache the subValues so we only need to create each one once (same in Bytes below) @Override public float[] get(int ord) throws IOException { @@ -894,7 +895,7 @@ public float[] get(int ord) throws IOException { // We need to implement fully random-access API here in order to support callers like // SortingCodecReader that rely on it. int newSubIndex = findSub(ord, lastSubIndex, starts); - if (newSubIndex != lastSubIndex) { + if (newSubIndex != lastSubIndex || subValues == null) { lastSubIndex = newSubIndex; assert subs.get(lastSubIndex).sub != null; subValues = subs.get(lastSubIndex).sub.vectors(); @@ -963,7 +964,7 @@ public int size() { @Override public Bytes vectors() { return new Bytes() { - int lastSubIndex = -1; + int lastSubIndex = 0; Bytes subValues; @Override @@ -973,7 +974,7 @@ public byte[] get(int ord) throws IOException { // SortingCodecReader that rely on it. We maintain lastSubIndex since we expect some // repetition. int newSubIndex = findSub(ord, lastSubIndex, starts); - if (newSubIndex != lastSubIndex) { + if (newSubIndex != lastSubIndex || subValues == null) { lastSubIndex = newSubIndex; assert subs.get(lastSubIndex).sub != null; subValues = subs.get(lastSubIndex).sub.vectors();