{"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/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L55-L91","documentation":"Thrown as ExtensionConfigurationException by DefaultLocaleExtension.createFromLanguageTag when @DefaultLocale is configured with the 'value' (language tag) attribute AND any of language, country, variant, or a non-default localeProvider are also set. The 'value' attribute must be used alone — it maps to Locale.forLanguageTag and is mutually exclusive with the parts-based and provider-based configuration modes.","triggerScenarios":"Annotating a test with @DefaultLocale(value = \"en-US\", language = \"en\"), or @DefaultLocale(value = \"en-US\", country = \"US\"), or @DefaultLocale(value = \"en-US\", localeProvider = MyProvider.class). Any combination of value with another attribute triggers it.","commonSituations":"Copy-pasting a @DefaultLocale declaration and adding value= on top of an existing language=/country= configuration; misunderstanding that value= is the BCP-47 tag form and cannot be mixed with the parts form.","solutions":["Use ONLY value= with a BCP-47 language tag: @DefaultLocale(value = \"en-US\").","If you need parts-based configuration, remove value= and use language=/country=/variant=.","If you need a provider, remove value=, language=, country=, variant= and set only localeProvider=."],"exampleFix":"// before\n@DefaultLocale(value = \"en-US\", language = \"en\", country = \"US\")\nvoid test() {}\n\n// after — pick ONE mode; here the BCP-47 tag form\n@DefaultLocale(value = \"en-US\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"// Inspect the annotation before the test runs (e.g. in a static check)\nDefaultLocale d = testClass.getAnnotation(DefaultLocale.class);\nboolean valueSet = !d.value().isEmpty();\nboolean partsSet = !d.language().isEmpty() || !d.country().isEmpty() || !d.variant().isEmpty();\nboolean providerSet = d.localeProvider() != NullLocaleProvider.class;\nif (valueSet && (partsSet || providerSet)) {\n    throw new IllegalStateException(\"@DefaultLocale value= cannot be combined with parts or provider\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use exactly one of: value= (BCP-47 tag), language=/country=/variant= (parts), or localeProvider= (provider).","Never combine value= with any other attribute.","Add a unit test that asserts your base test class's @DefaultLocale is well-formed."],"tags":["default-locale","extension-configuration","annotation-misuse","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}