{"id":"32579bbdc7120199","repo":"junit-team/junit5","slug":"systempropertyextension-was-configured-to-set-clea","errorCode":null,"errorMessage":"SystemPropertyExtension was configured to set/clear %s [%s] more than once by [%s].","messagePattern":"SystemPropertyExtension was configured to set/clear (.+?) \\[(.+?)\\] more than once by \\[(.+?)\\]\\.","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/SystemPropertiesModification.java","lineNumber":149,"sourceCode":"\t\t\t\t});\n\n\t\trequireUniqueEntries(element, duplicatePropertyNames);\n\t\treturn entries;\n\t}\n\n\tprivate static void requireNoClearAndSetSameEntries(AnnotatedElement element, Set<String> entriesToClear,\n\t\t\tSet<String> entriesToSet) {\n\t\trequireUniqueEntries(element, //\n\t\t\tentriesToClear.stream() //\n\t\t\t\t\t.filter(entriesToSet::contains) //\n\t\t\t\t\t.collect(toSet()));\n\t}\n\n\tprivate static void requireUniqueEntries(AnnotatedElement annotatedElement, Set<String> duplicatePropertNames) {\n\t\tif (duplicatePropertNames.isEmpty()) {\n\t\t\treturn;\n\t\t}\n\t\tthrow new ExtensionConfigurationException(\n\t\t\t\"SystemPropertyExtension was configured to set/clear %s [%s] more than once by [%s].\" //\n\t\t\t\t\t.formatted( //\n\t\t\t\t\t\tduplicatePropertNames.size() == 1 ? \"property\" : \"properties\", //\n\t\t\t\t\t\tString.join(\", \", duplicatePropertNames), //\n\t\t\t\t\t\tannotatedElement //\n\t\t\t\t\t));\n\t}\n}\n","sourceCodeStart":131,"sourceCodeEnd":158,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/SystemPropertiesModification.java#L131-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Deduplicate the entries: keep exactly one @SetSystemProperty per key per element.","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.","Audit the annotated element named in the error message and remove the conflicting entry."],"exampleFix":"// before\n@SetSystemProperty(key = \"flag\", value = \"a\")\n@SetSystemProperty(key = \"flag\", value = \"b\")\nvoid test() {}\n\n// after\n@SetSystemProperty(key = \"flag\", value = \"b\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"java.util.List<SetSystemProperty> sets = org.junit.platform.commons.support.AnnotationSupport\n    .findRepeatableAnnotations(element, SetSystemProperty.class);\njava.util.List<ClearSystemProperty> clears = org.junit.platform.commons.support.AnnotationSupport\n    .findRepeatableAnnotations(element, ClearSystemProperty.class);\njava.util.Set<String> setKeys = sets.stream().map(SetSystemProperty::key).collect(java.util.stream.Collectors.toSet());\njava.util.Set<String> clearKeys = clears.stream().map(ClearSystemProperty::key).collect(java.util.stream.Collectors.toSet());\njava.util.Set<String> conflict = new java.util.HashSet<>(setKeys); conflict.retainAll(clearKeys);\nif (setKeys.size() != sets.size() || !conflict.isEmpty()) {\n    throw new IllegalStateException(\"duplicate or conflicting @Set/@ClearSystemProperty keys on \" + element);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use at most one @SetSystemProperty per key per annotated element.","Never both set and clear the same key on the same element; move one to an enclosing/enclosed scope.","After merging branches, grep for duplicate key= attributes in @SetSystemProperty on the same method/class."],"tags":["system-properties","extension-configuration","duplicate-key","annotation-misuse","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}