{"record":{"id":"e39403a9f01d22c0","repo":"junit-team/junit5","slug":"defaultlocale-can-only-be-used-with-language-tag","errorCode":null,"errorMessage":"@DefaultLocale can only be used with language tag if language, country, variant and provider are not set","messagePattern":"@DefaultLocale can only be used with language tag if language, country, variant and provider are not set","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java","lineNumber":73,"sourceCode":"\t\t\t\t.map(DefaultLocaleExtension::createLocale);\n\t}\n\n\tprivate static Locale createLocale(DefaultLocale annotation) {\n\t\tif (!annotation.value().isEmpty()) {\n\t\t\treturn createFromLanguageTag(annotation);\n\t\t}\n\t\telse if (!annotation.language().isEmpty()) {\n\t\t\treturn createFromParts(annotation);\n\t\t}\n\t\telse {\n\t\t\treturn getFromProvider(annotation);\n\t\t}\n\t}\n\n\tprivate static Locale createFromLanguageTag(DefaultLocale annotation) {\n\t\tif (!annotation.language().isEmpty() || !annotation.country().isEmpty() || !annotation.variant().isEmpty()\n\t\t\t\t|| annotation.localeProvider() != NullLocaleProvider.class) {\n\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"@DefaultLocale can only be used with language tag if language, country, variant and provider are not set\");\n\t\t}\n\t\treturn Locale.forLanguageTag(annotation.value());\n\t}\n\n\tprivate static Locale createFromParts(DefaultLocale annotation) {\n\t\tif (annotation.localeProvider() != NullLocaleProvider.class)\n\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"@DefaultLocale can only be used with language tag if provider is not set\");\n\t\tString language = annotation.language();\n\t\tString country = annotation.country();\n\t\tString variant = annotation.variant();\n\t\tif (!language.isEmpty() && !country.isEmpty() && !variant.isEmpty()) {\n\t\t\treturn JupiterLocaleUtils.createLocale(language, country, variant);\n\t\t}\n\t\telse if (!language.isEmpty() && !country.isEmpty()) {\n\t\t\treturn JupiterLocaleUtils.createLocale(language, country);\n\t\t}","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L55-L91","documentation":"ExtensionConfigurationException from DefaultLocaleExtension.createFromLanguageTag, raised when @DefaultLocale is given a language tag (the value() attribute) but one or more of language, country, variant, or a custom localeProvider are also set. The annotation is mutually exclusive: a BCP-47 tag cannot be combined with explicit parts or a provider.","triggerScenarios":"Annotating a test with @DefaultLocale(value = \"en-US\", language = \"en\") (or with country/variant/localeProvider populated). createFromLanguageTag is selected whenever value() is non-empty, and the guard rejects any other populated field.","commonSituations":"Copy-pasting @DefaultLocale examples and leaving defaults; incrementally adding country= after first using a tag; mixing the tag-based and parts-based styles during refactoring.","solutions":["Use ONLY the value language tag: @DefaultLocale(\"en-US\") and remove language/country/variant/localeProvider.","OR switch fully to the parts form: drop value and set language (and optionally country/variant).","Audit the annotation to ensure exactly one configuration style is present."],"exampleFix":"// before\n@DefaultLocale(value = \"en-US\", language = \"en\", country = \"US\")\nvoid test() {}\n// after\n@DefaultLocale(\"en-US\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"boolean hasTag = !annotation.value().isEmpty();\nboolean hasParts = !annotation.language().isEmpty() || !annotation.country().isEmpty()\n        || !annotation.variant().isEmpty();\nboolean hasProvider = annotation.localeProvider() != NullLocaleProvider.class;\nif (hasTag && (hasParts || hasProvider)) {\n    // pick one style\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exactly one @DefaultLocale style: tag, parts, or provider.","Reset all unrelated attributes when switching styles.","Treat value (tag) as exclusive with language/country/variant/provider."],"tags":["default-locale","extension-config","mutual-exclusion","annotation-misuse"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}