junit-team/junit5 · critical · IllegalStateException

Could not add entry to the queue for task: ${entry.task}

Error message

Could not add entry to the queue for task: ${entry.task}

What it means

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.

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 956246301e)

Solutions

  1. File a JUnit issue with the full stack trace; this is an executor-internal invariant violation, not a configuration error.
  2. As a workaround, disable parallel execution (junit.jupiter.execution.parallel.enabled=false) to avoid the WorkerThreadPool code path.
  3. Audit any custom SelectorResolver / Node.Task that might produce non-unique UniqueIds or recursive submissions.
  4. Upgrade to the latest JUnit Platform release; duplicate-enqueue bugs are typically fixed promptly.
Defensive patterns

Strategy: try-catch

Try / catch

try {
    executorService.submit(testTask);
} catch (IllegalStateException e) {
    if (e.getMessage().contains("Could not add entry to the queue")) {
        // internal invariant violation; collect diagnostics and report upstream
        log.error("JUnit executor invariant violation", e);
    }
    throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/e3699c8d5d66bfcc.json. Report an issue: GitHub.