junit-team/junit5 · error · ExtensionConfigurationException

SystemPropertyExtension was configured to set/clear %s [%s]

Error message

SystemPropertyExtension was configured to set/clear %s [%s] more than once by [%s].

What it means

Thrown as ExtensionConfigurationException by SystemPropertiesModification.requireUniqueEntries (via requireNoClearAndSetSameEntries) when the same system property key is configured twice on the same annotated element — either declared twice via @SetSystemProperty, twice via @ClearSystemProperty, or both set and cleared on the same element. The extension refuses ambiguous configurations at parse time.

Source

Thrown at junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/SystemPropertiesModification.java:149

				});

		requireUniqueEntries(element, duplicatePropertyNames);
		return entries;
	}

	private static void requireNoClearAndSetSameEntries(AnnotatedElement element, Set<String> entriesToClear,
			Set<String> entriesToSet) {
		requireUniqueEntries(element, //
			entriesToClear.stream() //
					.filter(entriesToSet::contains) //
					.collect(toSet()));
	}

	private static void requireUniqueEntries(AnnotatedElement annotatedElement, Set<String> duplicatePropertNames) {
		if (duplicatePropertNames.isEmpty()) {
			return;
		}
		throw new ExtensionConfigurationException(
			"SystemPropertyExtension was configured to set/clear %s [%s] more than once by [%s]." //
					.formatted( //
						duplicatePropertNames.size() == 1 ? "property" : "properties", //
						String.join(", ", duplicatePropertNames), //
						annotatedElement //
					));
	}
}

View on GitHub (pinned to 956246301e)

Solutions

  1. Deduplicate the entries: keep exactly one @SetSystemProperty per key per element.
  2. If you intend to clear and reset, split across lifecycle boundaries (e.g., clear at class level, set at method level) rather than on the same element.
  3. Audit the annotated element named in the error message and remove the conflicting entry.

Example fix

// before
@SetSystemProperty(key = "flag", value = "a")
@SetSystemProperty(key = "flag", value = "b")
void test() {}

// after
@SetSystemProperty(key = "flag", value = "b")
void test() {}
Defensive patterns

Strategy: validation

Validate before calling

java.util.List<SetSystemProperty> sets = org.junit.platform.commons.support.AnnotationSupport
    .findRepeatableAnnotations(element, SetSystemProperty.class);
java.util.List<ClearSystemProperty> clears = org.junit.platform.commons.support.AnnotationSupport
    .findRepeatableAnnotations(element, ClearSystemProperty.class);
java.util.Set<String> setKeys = sets.stream().map(SetSystemProperty::key).collect(java.util.stream.Collectors.toSet());
java.util.Set<String> clearKeys = clears.stream().map(ClearSystemProperty::key).collect(java.util.stream.Collectors.toSet());
java.util.Set<String> conflict = new java.util.HashSet<>(setKeys); conflict.retainAll(clearKeys);
if (setKeys.size() != sets.size() || !conflict.isEmpty()) {
    throw new IllegalStateException("duplicate or conflicting @Set/@ClearSystemProperty keys on " + element);
}

Prevention

When it happens

Trigger: Annotating one element with two @SetSystemProperty(key="foo", value="a") and @SetSystemProperty(key="foo", value="b"); or @SetSystemProperty(key="foo", ...) together with @ClearSystemProperty(key="foo") on the same class or method.

Common situations: Copy-paste of a @SetSystemProperty declaration producing a duplicate key; merging configurations from two developers; refactoring that left a stale entry next to a new one.

Related errors


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