junit-team/junit5 · error · ExtensionConfigurationException

SystemPropertyExtension was configured to set/clear

Error message

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

What it means

ExtensionConfigurationException from SystemPropertiesModification.requireUniqueEntries, raised when the same system-property key is set/cleared more than once by the same @SetSystemProperty / @ClearSystemProperty annotations on one element — either two @SetSystemProperty(key=...) with the same key, or both a clear and a set for the same key. The extension refuses ambiguous configurations rather than applying one nondeterministically.

Solutions

  1. Deduplicate @SetSystemProperty entries on the element so each key appears at most once.
  2. Remove either the @ClearSystemProperty or the @SetSystemProperty for a key that has both — pick one intent.
  3. If you need different values per test, split into separate test methods or use a parameter source.

Example fix

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

Strategy: validation

Validate before calling

Set<String> setKeys = new HashSet<>();
for (SetSystemProperty a : element.getAnnotationsByType(SetSystemProperty.class)) {
    if (!setKeys.add(a.key())) { /* duplicate set key */ }
}
Set<String> clearKeys = Arrays.stream(element.getAnnotationsByType(ClearSystemProperty.class))
        .map(ClearSystemProperty::key).collect(toSet());
setKeys.retainAll(clearKeys);
if (!setKeys.isEmpty()) { /* clear+set conflict */ }

Prevention

When it happens

Trigger: Repeated @SetSystemProperty(key="foo", value="a") and @SetSystemProperty(key="foo", value="b") on one test; or @ClearSystemProperty(key="foo") together with @SetSystemProperty(key="foo", ...) on the same element. findEntriesToSet detects duplicate keys; requireNoClearAndSetSameEntries detects clear∩set overlap.

Common situations: Merging annotations from a base test and an override; composing meta-annotations that both set the same key; copy-paste of a SetSystemProperty leaving a duplicate key behind.

Related errors


AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11). Data as JSON: /api/errors/32579bbdc7120199. Report an issue: GitHub.

Appendix: 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 f070c699a0)