{"record":{"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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/JupiterPropertyUtils.java#L23-L50","documentation":"ExtensionConfigurationException from JupiterPropertyUtils.throwIfHasObservableDefaults, raised when the SystemPropertiesExtension is asked to snapshot/restore system properties but the current Properties object has observable default properties (entries reachable only via stringPropertyNames() but not in the main keySet()). Because Properties.clone() does not copy defaults, a restore would silently lose those default-backed entries, so JUnit refuses rather than produce an inaccurate snapshot.","triggerScenarios":"Test code or a prior extension calls System.getProperties().defaults = ... (or sets defaults via a Properties subclass) before the SystemPropertiesExtension tries to capture the snapshot for restoration.","commonSituations":"A @BeforeEach or static initializer that seeds System properties with defaults; third-party libraries (logging, config libs) that install default system properties; chaining Properties objects for layered lookups.","solutions":["Avoid setting System.getProperties() defaults before the test; use explicit System.setProperty() entries which the extension can snapshot correctly.","If defaults are required, set them after the extension's snapshot is taken, or clear them before the test runs.","Disable restore behavior for the affected property set if accurate snapshotting is impossible in your environment."],"exampleFix":"// before\nProperties p = System.getProperties();\np.defaults = new Properties(Map.of(\"legacy.flag\", \"1\"));\n// after\nSystem.setProperty(\"legacy.flag\", \"1\"); // snapshot-able","handlingStrategy":"validation","validationCode":"Properties p = System.getProperties();\nSet<Object> keys = p.keySet();\nList<String> defaults = p.stringPropertyNames().stream()\n        .filter(n -> !keys.contains(n)).toList();\nif (!defaults.isEmpty()) { /* clear defaults before snapshot */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer System.setProperty over installing Properties defaults.","Clear any installed defaults before the SystemPropertiesExtension runs.","Avoid chaining Properties objects onto System.getProperties()."],"tags":["system-properties","snapshot","defaults","extension-config","properties-clone"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}