{"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/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L78-L114","documentation":"Thrown as ExtensionConfigurationException by DefaultLocaleExtension.createFromParts when parts-based @DefaultLocale configuration is internally inconsistent: language is set but country is empty and variant is non-empty. The only valid parts-based shapes are language alone, language+country, or language+country+variant — variant without country is not a legal Locale.","triggerScenarios":"Annotating a test with @DefaultLocale(language = \"en\", variant = \"POSIX\") (no country). Also reached if country is somehow empty while variant is set, regardless of which attribute the developer thought they were configuring.","commonSituations":"Misunderstanding the Locale(language, country, variant) constructor contract (variant requires country); trimming a @DefaultLocale down and accidentally removing country= but leaving variant=.","solutions":["Add the missing country attribute: @DefaultLocale(language = \"en\", country = \"US\", variant = \"POSIX\").","If you did not intend a variant, remove variant= and use language alone or language+country.","Prefer the BCP-47 tag form @DefaultLocale(value = \"en-US-POSIX\") which lets Locale.forLanguageTag normalize the parts."],"exampleFix":"// before\n@DefaultLocale(language = \"en\", variant = \"POSIX\")\nvoid test() {}\n\n// after — variant requires a country\n@DefaultLocale(language = \"en\", country = \"US\", variant = \"POSIX\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"DefaultLocale d = testClass.getAnnotation(DefaultLocale.class);\nboolean l = !d.language().isEmpty(), c = !d.country().isEmpty(), v = !d.variant().isEmpty();\nboolean validParts = l || c || v\n    ? (l && !v) || (l && c) // language alone, language+country[+variant]\n    : true;\nif (!validParts) {\n    throw new IllegalStateException(\"@DefaultLocale parts require language, and variant requires country\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Variant requires country; country requires language. The only valid stacks are L, L+C, L+C+V.","Prefer @DefaultLocale(value = \"en-US-POSIX\") to let the JVM normalize parts for you.","Double-check trimmed-down @DefaultLocale annotations to ensure no orphan variant= or country=."],"tags":["default-locale","extension-configuration","annotation-misuse","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}