{"id":"e3699c8d5d66bfcc","repo":"junit-team/junit5","slug":"could-not-add-entry-to-the-queue-for-task-entry","errorCode":null,"errorMessage":"Could not add entry to the queue for task: ${entry.task}","messagePattern":"Could not add entry to the queue for task: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/WorkerThreadPoolHierarchicalTestExecutorService.java","lineNumber":693,"sourceCode":"\t\tEntry add(TestTask task, int index) {\n\t\t\tEntry entry = new Entry(task, index);\n\t\t\tlogger.trace(() -> \"forking: \" + entry.task);\n\t\t\treturn doAdd(entry);\n\t\t}\n\n\t\tvoid addAll(Collection<Entry> entries) {\n\t\t\tentries.forEach(this::doAdd);\n\t\t}\n\n\t\tvoid reAdd(Entry entry) {\n\t\t\tlogger.trace(() -> \"re-enqueuing: \" + entry.task);\n\t\t\tdoAdd(entry);\n\t\t}\n\n\t\tprivate Entry doAdd(Entry entry) {\n\t\t\tvar added = queue.add(entry);\n\t\t\tif (!added) {\n\t\t\t\tthrow new IllegalStateException(\"Could not add entry to the queue for task: \" + entry.task);\n\t\t\t}\n\t\t\treturn entry;\n\t\t}\n\n\t\tboolean remove(Entry entry) {\n\t\t\treturn queue.remove(entry);\n\t\t}\n\n\t\tboolean isEmpty() {\n\t\t\treturn queue.isEmpty();\n\t\t}\n\n\t\t@Override\n\t\tpublic Iterator<Entry> iterator() {\n\t\t\treturn queue.iterator();\n\t\t}\n\n\t\tprivate static final class Entry {","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/WorkerThreadPoolHierarchicalTestExecutorService.java#L675-L711","documentation":"Thrown by WorkQueue.doAdd (line 690-695) as an IllegalStateException when ConcurrentSkipListSet.add(entry) returns false, i.e. an Entry equal to one already in the queue was added again. Entry equality (line 761-770) is based on (uniqueId, index), so a duplicate add implies the same UniqueId at the same child index was enqueued twice. This is an internal invariant of the WorkerThreadPool executor and signals a logic bug rather than a user config issue.","triggerScenarios":"The executor's bookkeeping re-enqueues an Entry whose (uniqueId, index) pair is already pending (e.g. a reAdd() on an entry still in the queue, or a forkAll path that double-counts a child). Reached during parallel test execution with WorkerThreadPoolHierarchicalTestExecutorService (default parallel executor since 6.1).","commonSituations":"An engine bug or a pathological test hierarchy producing duplicate UniqueIds at the same nesting index under concurrent execution; custom Node.Task implementations that re-submit themselves; races when two code paths enqueue the same descriptor.","solutions":["File a JUnit issue with the full stack trace; this is an executor-internal invariant violation, not a configuration error.","As a workaround, disable parallel execution (junit.jupiter.execution.parallel.enabled=false) to avoid the WorkerThreadPool code path.","Audit any custom SelectorResolver / Node.Task that might produce non-unique UniqueIds or recursive submissions.","Upgrade to the latest JUnit Platform release; duplicate-enqueue bugs are typically fixed promptly."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    executorService.submit(testTask);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Could not add entry to the queue\")) {\n        // internal invariant violation; collect diagnostics and report upstream\n        log.error(\"JUnit executor invariant violation\", e);\n    }\n    throw e;\n}","preventionTips":["Keep JUnit Platform on the latest patch release; internal executor bugs get fixed there.","Audit custom Node.Task/SelectorResolver for non-unique UniqueIds or recursive submissions.","Disable parallel execution as a workaround if the bug blocks CI."],"tags":["junit-platform","parallel-execution","worker-thread-pool","threading","engine-internal","invariant-violation"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}