{"id":"eedcce7995afef20","repo":"junit-team/junit5","slug":"defaultlocale-can-only-be-used-with-a-provider-if","errorCode":null,"errorMessage":"@DefaultLocale can only be used with a provider if value, language, country and variant are not set.","messagePattern":"@DefaultLocale can only be used with a provider if value, language, country and variant 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":104,"sourceCode":"\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}\n\t\treturn invoke(provider);\n\t}\n\n\t@SuppressWarnings(\"ConstantValue\")\n\tprivate static Locale invoke(LocaleProvider provider) {\n\t\tvar locale = provider.get();\n\t\tif (locale == null) {\n\t\t\tthrow new ExtensionConfigurationException(\"LocaleProvider instance returned with null\");","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L86-L122","documentation":"Thrown as ExtensionConfigurationException by DefaultLocaleExtension.getFromProvider when @DefaultLocale is in provider mode (value and language empty) but country= or variant= is set. The provider is the sole source of the Locale; country and variant must not be combined with it.","triggerScenarios":"Annotating a test with @DefaultLocale(country = \"US\", localeProvider = MyProvider.class) or @DefaultLocale(variant = \"POSIX\", localeProvider = MyProvider.class) without setting value or language.","commonSituations":"Trying to 'augment' a provider-supplied Locale with extra parts; partial migration where country= was left behind when switching to provider mode.","solutions":["Remove country= and variant= when using localeProvider=; let the provider return the full Locale.","If you need specific parts, switch to parts-based mode (language=/country=/variant=) and remove localeProvider=."],"exampleFix":"// before\n@DefaultLocale(country = \"US\", localeProvider = MyLocaleProvider.class)\nvoid test() {}\n\n// after — provider mode is exclusive\n@DefaultLocale(localeProvider = MyLocaleProvider.class)\nvoid test() {}","handlingStrategy":"validation","validationCode":"DefaultLocale d = testClass.getAnnotation(DefaultLocale.class);\nboolean providerMode = d.value().isEmpty() && d.language().isEmpty();\nboolean providerSet = d.localeProvider() != NullLocaleProvider.class;\nif (providerMode && providerSet && (!d.country().isEmpty() || !d.variant().isEmpty())) {\n    throw new IllegalStateException(\"@DefaultLocale provider cannot be combined with country= or variant=\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When using localeProvider=, leave value=, language=, country=, and variant= all unset.","Audit annotations after switching configuration modes."],"tags":["default-locale","extension-configuration","annotation-misuse","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}