{"record":{"id":"933d2eb922832bed","repo":"junit-team/junit5","slug":"defaultlocale-not-configured-correctly-when-not","errorCode":null,"errorMessage":"@DefaultLocale not configured correctly. When not using a language tag, specify either language, or language and country, or language and country and variant.","messagePattern":"@DefaultLocale not configured correctly\\. When not using a language tag, specify either language, or language and country, or language and country and variant\\.","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java","lineNumber":96,"sourceCode":"\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}\n\t\telse if (!language.isEmpty() && variant.isEmpty()) {\n\t\t\treturn JupiterLocaleUtils.createLocale(language);\n\t\t}\n\t\telse {\n\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"@DefaultLocale not configured correctly. When not using a language tag, specify either\"\n\t\t\t\t\t\t+ \" language, or language and country, or language and country and variant.\");\n\t\t}\n\t}\n\n\tprivate static Locale getFromProvider(DefaultLocale annotation) {\n\t\tif (!annotation.country().isEmpty() || !annotation.variant().isEmpty())\n\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"@DefaultLocale can only be used with a provider if value, language, country and variant are not set.\");\n\t\tvar providerClass = annotation.localeProvider();\n\t\tLocaleProvider provider;\n\t\ttry {\n\t\t\tprovider = ReflectionSupport.newInstance(providerClass);\n\t\t}\n\t\tcatch (Exception exception) {\n\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"LocaleProvider instance could not be constructed because of an exception\", exception);\n\t\t}","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L78-L114","documentation":"ExtensionConfigurationException from DefaultLocaleExtension.createFromParts, thrown when neither the tag form nor a valid combination of parts was supplied. Valid parts combinations are: language alone; language+country; language+country+variant. Anything else (e.g. country without language, or variant without language+country) is rejected.","triggerScenarios":"Annotating a test with @DefaultLocale(country = \"US\") (no language), @DefaultLocale(variant = \"...\"), or @DefaultLocale(language = \"\", country = \"US\", variant = \"...\"). None of the if/else-if branches in createFromParts match, so the final else throws.","commonSituations":"Assuming country alone selects a locale; typos leaving language blank; trimming an annotation down and forgetting language is mandatory.","solutions":["Always include language when using the parts form, then add country and variant as needed.","Use the value tag form (@DefaultLocale(\"en-US\")) if you only have a region, which is simpler.","Re-read the message — it lists the three valid combinations; match one exactly."],"exampleFix":"// before\n@DefaultLocale(country = \"US\")\nvoid test() {}\n// after\n@DefaultLocale(language = \"en\", country = \"US\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"boolean l = !annotation.language().isEmpty();\nboolean c = !annotation.country().isEmpty();\nboolean v = !annotation.variant().isEmpty();\nboolean validParts = l && !v || l && c; // language, language+country, or all three\nif (!validParts) { /* fix annotation */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Language is mandatory in the parts form of @DefaultLocale.","Variant requires both language and country.","Prefer the tag form @DefaultLocale(\"en-US\") when unsure."],"tags":["default-locale","extension-config","validation","annotation-misuse"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}