{"id":"e469c81b4d2a696a","repo":"junit-team/junit5","slug":"systempropertiesextension-was-configured-to-restor","errorCode":null,"errorMessage":"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","messagePattern":"SystemPropertiesExtension was configured to restore the system properties by \\[(.+?)\\]\\. However, it was not possible to create an accurate snapshot of the system properties using Properties::clone, because default properties were present: (.+?)","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/JupiterPropertyUtils.java","lineNumber":41,"sourceCode":"\t\t/* no-op */\n\t}\n\n\tstatic Properties cloneWithoutDefaults(ExtensionContext context, Properties properties) {\n\t\t// Custom implementations have to implement clone correctly.\n\t\tif (properties.getClass() == Properties.class) {\n\t\t\tthrowIfHasObservableDefaults(context, properties);\n\t\t}\n\t\treturn (Properties) properties.clone();\n\t}\n\n\tprivate static void throwIfHasObservableDefaults(ExtensionContext context, Properties properties) {\n\t\tSet<Object> keySet = properties.keySet();\n\t\t// A best effort check.\n\t\tList<String> defaultPropertyNames = properties.stringPropertyNames().stream() //\n\t\t\t\t.filter(propertyName -> !keySet.contains(propertyName)) //\n\t\t\t\t.toList();\n\t\tif (!defaultPropertyNames.isEmpty()) {\n\t\t\tthrow new ExtensionConfigurationException(\"\"\"\n\t\t\t\t\tSystemPropertiesExtension was configured to restore the system properties by [%s]. \\\n\t\t\t\t\tHowever, it was not possible to create an accurate snapshot of the system properties \\\n\t\t\t\t\tusing Properties::clone, because default properties were present: %s\"\"\" //\n\t\t\t\t\t.formatted(context.getElement().orElseThrow(), defaultPropertyNames));\n\t\t}\n\t}\n\n}\n","sourceCodeStart":23,"sourceCodeEnd":50,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/JupiterPropertyUtils.java#L23-L50","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — somewhere a default was set\nSystem.getProperties().setDefaults(myDefaults);\n\n// after — do not attach defaults to the live system properties\n// store your fallbacks in a separate Properties instance and consult them in your own code","handlingStrategy":"validation","validationCode":"java.util.Properties sys = System.getProperties();\nif (sys.getClass() == java.util.Properties.class && sys.defaults != null) {\n    // Note: 'defaults' is protected; reflectively check or use stringPropertyNames() vs keySet()\n    java.util.Set<Object> keys = sys.keySet();\n    java.util.List<String> fromDefaults = sys.stringPropertyNames().stream()\n        .filter(k -> !keys.contains(k)).toList();\n    if (!fromDefaults.isEmpty()) {\n        throw new IllegalStateException(\"System properties have defaults; remove them before using SystemPropertiesExtension: \" + fromDefaults);\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["system-properties","extension-configuration","properties-clone","snapshot","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}