{"record":{"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":"error","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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/WorkerThreadPoolHierarchicalTestExecutorService.java#L675-L711","documentation":"WorkQueue.doAdd throws IllegalStateException when ConcurrentSkipListSet.add(entry) returns false. A set refuses a duplicate (per its comparator), so this means an Entry equal to an existing one was already present. The comparator orders by level/container-flag/index/uniqueId, so two entries with identical (level, isContainer, index, uniqueId) are considered duplicates.","triggerScenarios":"Calling WorkQueue.add / addAll / reAdd with an Entry whose (level, isContainer, index, uniqueId) tuple equals an Entry already in the queue. This is an internal invariant violation inside WorkerThreadPoolHierarchicalTestExecutorService scheduling, typically from re-enqueuing a task that is still queued, or two forks producing the same uniqueId/index.","commonSituations":"Internal scheduler bug or race where the same TestTask entry is submitted twice without being removed first; duplicate UniqueIds in the test graph (two tests share a UniqueId) causing the comparator to treat distinct tasks as equal; custom HierarchicalTestExecutorService misuse that double-schedules entries.","solutions":["Check for duplicate UniqueIds in the test descriptor tree (two tests resolving to the same id) and disambiguate them (e.g. @ParameterizedTest indices, custom display names).","If you author custom scheduling code, call remove(entry) before reAdd(entry), or never re-add an entry that is still queued.","If this occurs with stock engines and no custom code, report it as a JUnit platform bug with the entry.task details."],"exampleFix":"// before - re-add without removing\nqueue.reAdd(entry); // throws if entry still present\n// after - remove first, then re-add\nqueue.remove(entry);\nqueue.reAdd(entry);","handlingStrategy":"validation","validationCode":"// Before re-adding, ensure it is absent; this is internal-API level guidance\nif (!queue.contains(entry)) queue.reAdd(entry);\n// And ensure UniqueIds in the descriptor tree are distinct.","typeGuard":null,"tryCatchPattern":"try {\n    queue.reAdd(entry);\n} catch (IllegalStateException e) {\n    // duplicate enqueue - log entry.task and verify no duplicate UniqueId\n}","preventionTips":["Guarantee every TestDescriptor has a unique UniqueId in the tree.","remove(entry) before reAdd(entry) when re-enqueuing.","Avoid double-submitting the same task entry from custom scheduling code."],"tags":["scheduler","work-queue","duplicate","concurrent"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}