junit-team/junit5 · error · IllegalStateException
Could not add entry to the queue for task
Error message
Could not add entry to the queue for task: ${entry.task} What it means
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.
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.
Example fix
// before - re-add without removing queue.reAdd(entry); // throws if entry still present // after - remove first, then re-add queue.remove(entry); queue.reAdd(entry);
Defensive patterns
Strategy: validation
Validate before calling
// Before re-adding, ensure it is absent; this is internal-API level guidance if (!queue.contains(entry)) queue.reAdd(entry); // And ensure UniqueIds in the descriptor tree are distinct.
Try / catch
try {
queue.reAdd(entry);
} catch (IllegalStateException e) {
// duplicate enqueue - log entry.task and verify no duplicate UniqueId
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/e3699c8d5d66bfcc.
Report an issue: GitHub.
Appendix: source
Thrown at junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/WorkerThreadPoolHierarchicalTestExecutorService.java:693
Entry add(TestTask task, int index) {
Entry entry = new Entry(task, index);
logger.trace(() -> "forking: " + entry.task);
return doAdd(entry);
}
void addAll(Collection<Entry> entries) {
entries.forEach(this::doAdd);
}
void reAdd(Entry entry) {
logger.trace(() -> "re-enqueuing: " + entry.task);
doAdd(entry);
}
private Entry doAdd(Entry entry) {
var added = queue.add(entry);
if (!added) {
throw new IllegalStateException("Could not add entry to the queue for task: " + entry.task);
}
return entry;
}
boolean remove(Entry entry) {
return queue.remove(entry);
}
boolean isEmpty() {
return queue.isEmpty();
}
@Override
public Iterator<Entry> iterator() {
return queue.iterator();
}
private static final class Entry {View on GitHub (pinned to f070c699a0)