Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: use sentinel instead of null in storyQueue to avoid NPE
LinkedBlockingQueue.put(null) throws NullPointerException. Replace the
nullable queue with a String queue and map null to/from a DONE_SENTINEL
so callers can still use pushStory(null) to signal completion.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
  • Loading branch information
EmilioBejasa and claude committed Mar 30, 2026
commit 16e53e78d7fa69603ae49f0aafde6ba39ab4398f
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class StorybookRegistry(reactContext: ReactApplicationContext) : ReactContextBas

// Capacity 1 so pushStory() blocks until JS has consumed the current entry,
// giving natural back-pressure between the test runner and JS.
private val storyQueue = LinkedBlockingQueue<String?>(1)
// LinkedBlockingQueue does not allow null, so we use a sentinel to signal done.
private const val DONE_SENTINEL = "__done__"
private val storyQueue = LinkedBlockingQueue<String>(1)

@Volatile private var storyReadyLatch: CountDownLatch? = null

Expand All @@ -45,7 +47,7 @@ class StorybookRegistry(reactContext: ReactApplicationContext) : ReactContextBas
* Blocks until JS has consumed the previous entry (queue capacity = 1).
*/
fun pushStory(storyId: String?) {
storyQueue.put(storyId)
storyQueue.put(storyId ?: DONE_SENTINEL)
}

/**
Expand Down Expand Up @@ -103,8 +105,8 @@ class StorybookRegistry(reactContext: ReactApplicationContext) : ReactContextBas
@ReactMethod
fun awaitNextStory(promise: Promise) {
Thread {
val storyId = storyQueue.poll(30, TimeUnit.SECONDS)
promise.resolve(storyId)
val raw = storyQueue.poll(30, TimeUnit.SECONDS)
promise.resolve(if (raw == DONE_SENTINEL) null else raw)
}.start()
}

Expand Down
Loading