junit-team/junit5 · error · ExtensionConfigurationException
SystemPropertiesExtension was configured to restore the syst
Error message
SystemPropertiesExtension was configured to restore the system properties by [%s]. However, it was not possible to create an accurate snapshot of the system properties using Properties::clone, because default properties were present: %s
What it means
Thrown as ExtensionConfigurationException by JupiterPropertyUtils.throwIfHasObservableDefaults when the SystemPropertiesExtension tries to snapshot System.getProperties() in order to restore it later, and the Properties object is the concrete java.util.Properties type with non-null defaults. Properties.clone() does NOT copy the defaults map, so a restore based on such a clone would silently drop the defaults; JUnit refuses to take an inaccurate snapshot rather than corrupt state.
Source
Thrown at junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/JupiterPropertyUtils.java:41
/* no-op */
}
static Properties cloneWithoutDefaults(ExtensionContext context, Properties properties) {
// Custom implementations have to implement clone correctly.
if (properties.getClass() == Properties.class) {
throwIfHasObservableDefaults(context, properties);
}
return (Properties) properties.clone();
}
private static void throwIfHasObservableDefaults(ExtensionContext context, Properties properties) {
Set<Object> keySet = properties.keySet();
// A best effort check.
List<String> defaultPropertyNames = properties.stringPropertyNames().stream() //
.filter(propertyName -> !keySet.contains(propertyName)) //
.toList();
if (!defaultPropertyNames.isEmpty()) {
throw new ExtensionConfigurationException("""
SystemPropertiesExtension was configured to restore the system properties by [%s]. \
However, it was not possible to create an accurate snapshot of the system properties \
using Properties::clone, because default properties were present: %s""" //
.formatted(context.getElement().orElseThrow(), defaultPropertyNames));
}
}
}
View on GitHub (pinned to 956246301e)
Solutions
- Find and remove the code that adds defaults to the system Properties (search for setProperties( or .setDefaults( on System.getProperties()).
- If a dependency legitimately needs defaults, snapshot/restore System properties yourself in a @BeforeAll/@AfterAll using a deep copy rather than relying on the extension.
- Avoid mutating System.getProperties() directly; prefer System.setProperty() which does not introduce defaults.
Example fix
// before — somewhere a default was set System.getProperties().setDefaults(myDefaults); // after — do not attach defaults to the live system properties // store your fallbacks in a separate Properties instance and consult them in your own code
Defensive patterns
Strategy: validation
Validate before calling
java.util.Properties sys = System.getProperties();
if (sys.getClass() == java.util.Properties.class && sys.defaults != null) {
// Note: 'defaults' is protected; reflectively check or use stringPropertyNames() vs keySet()
java.util.Set<Object> keys = sys.keySet();
java.util.List<String> fromDefaults = sys.stringPropertyNames().stream()
.filter(k -> !keys.contains(k)).toList();
if (!fromDefaults.isEmpty()) {
throw new IllegalStateException("System properties have defaults; remove them before using SystemPropertiesExtension: " + fromDefaults);
}
} Prevention
- Never call System.getProperties().setDefaults(...); use System.setProperty() for individual entries.
- Audit dependencies that may replace System.getProperties() with a pre-loaded instance.
- If defaults are unavoidable, snapshot/restore System properties manually with a deep copy instead of the extension.
When it happens
Trigger: Some code in the JVM (test class, a previous extension, a static initializer, or a dependency) replaced System.getProperties() with a Properties that has a non-null defaults map, OR called Properties.setDefaults(...) on the system properties. When SystemPropertiesExtension then tries to back up, the default-property-name check trips.
Common situations: Libraries that wrap system properties with defaults (some logging or config frameworks); a previous test that did System.getProperties().setDefaults(...); a custom SecurityManager or agent that replaces System properties.
Related errors
- SystemPropertyExtension was configured to set/clear %s [%s]
- @DefaultLocale can only be used with language tag if languag
- @DefaultLocale can only be used with language tag if provide
- @DefaultLocale not configured correctly. When not using a la
- @DefaultLocale can only be used with a provider if value, la
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/e469c81b4d2a696a.json.
Report an issue: GitHub.