Skip to content

Commit

Permalink
fix: NullPointerException in postponed index lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
novoj committed Feb 6, 2025
1 parent 0c527aa commit 2ae764f
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class DiskRingBuffer {
* Contains set of postponed index updates, that were captured during initial session index creation.
* The reference is empty when no indexing is being done (i.e. almost always).
*/
private final AtomicReference<Deque<Runnable>> postponedIndexUpdates = new AtomicReference<>();
private final AtomicReference<Deque<Consumer<TrafficRecordingIndex>>> postponedIndexUpdates = new AtomicReference<>();
/**
* Transaction used for writing to the session index.
*/
Expand Down Expand Up @@ -410,19 +410,16 @@ public void sessionWritten(
ofNullable(this.postponedIndexUpdates.get())
.ifPresent(
postponedUpdates -> postponedUpdates.add(
() -> {
final TrafficRecordingIndex newIndex = this.sessionIndex.get();
newIndex.setupSession(
sessionLocation,
sessionId,
created,
durationInMillis,
fetchCount,
bytesFetchedTotal,
recordingTypes,
labels
);
}
theIndex -> theIndex.setupSession(
sessionLocation,
sessionId,
created,
durationInMillis,
fetchCount,
bytesFetchedTotal,
recordingTypes,
labels
)
)
);
}
Expand Down Expand Up @@ -555,10 +552,10 @@ public void indexData(
}

// index is ready, process postponed updates
final Deque<Runnable> theLambdasToExecute = this.postponedIndexUpdates.getAndSet(null);
final Deque<Consumer<TrafficRecordingIndex>> theLambdasToExecute = this.postponedIndexUpdates.getAndSet(null);
notNull(theLambdasToExecute, "Postponed index updates are null. This is not expected!");
theLambdasToExecute.forEach(lambda -> {
lambda.run();
lambda.accept(index);
this.indexedSessions.incrementAndGet();
});

Expand Down

0 comments on commit 2ae764f

Please sign in to comment.