Skip to content

Commit

Permalink
Added defensive coding for the cases where store() is still null cl…
Browse files Browse the repository at this point in the history
…oses #1643 (#1644)
  • Loading branch information
peter-lawrey authored Dec 3, 2024
1 parent 5fc274d commit 8650709
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public WireStore writePosition(long position) {
* @param index the index we wish to move to
* @return whether the index was found for reading.
*/
@Nullable
@NotNull
@Override
public ScanResult moveToIndexForRead(@NotNull ExcerptContext ec, long index) {
throwExceptionIfClosed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,10 @@ private ScanResult moveToIndexResult0(final long index) {
return NOT_REACHED;

index(index);
final ScanResult scanResult = this.store().moveToIndexForRead(this, sequenceNumber);
SingleChronicleQueueStore store0 = this.store();
if (store0 == null)
return NOT_REACHED;
final ScanResult scanResult = store0.moveToIndexForRead(this, sequenceNumber);
switch (scanResult) {
case FOUND:
Wire privateWire = privateWire();
Expand Down Expand Up @@ -1259,10 +1262,10 @@ int getIndexMoveCount() {
return moveToState.indexMoveCount;
}

@NotNull
private SingleChronicleQueueStore store() {
if (store == null)
setCycle(cycle());
if (!cycle(cycle()))
Jvm.warn().on(getClass(), "Unable to find cycle=" + cycle() + ", queue=" + queue.fileAbsolutePath());
return store;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* private static final String FILE = System.getProperty("file");
* private static final boolean SKIP_TABLE_STORE = Jvm.getBoolean("skipTableStoreDump");
* private static final boolean UNALIGNED = Jvm.getBoolean("dumpUnaligned");
* private static final int LENGTH = ", 0".length();
*/
public final class DumpMain {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3659,6 +3659,8 @@ public void testReadUsingReadOnly() {
public void lastIndexShouldReturnLastIndexForPopulatedQueue() {
File tmpDir = getTmpDir();
try (ChronicleQueue queue = SingleChronicleQueueBuilder.single(tmpDir).wireType(wireType).build()) {
assertEquals(-1, queue.lastIndex());

long actualLastIndex;
try (ExcerptAppender appender = queue.createAppender()) {
appender.writeText("Hello!");
Expand Down

0 comments on commit 8650709

Please sign in to comment.