{"record":{"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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L86-L122","documentation":"ExtensionConfigurationException from DefaultLocaleExtension.getFromProvider, raised when @DefaultLocale uses a localeProvider but also specifies country or variant. The provider form is exclusive: it must be the sole source of the Locale, so any country/variant (and value/language, enforced elsewhere) alongside it is rejected.","triggerScenarios":"Annotating a test with @DefaultLocale(localeProvider = MyProvider.class, country = \"US\") or with variant set. getFromProvider is selected when value and language are empty; it rejects non-empty country/variant.","commonSituations":"Adding a provider while leaving previously-set country/variant attributes in place; misunderstanding that the provider fully determines the locale.","solutions":["Remove country and variant (and value/language) so only localeProvider remains.","If you need parts alongside the provider, fold that logic into the provider's get() instead of the annotation."],"exampleFix":"// before\n@DefaultLocale(localeProvider = MyProvider.class, country = \"US\")\nvoid test() {}\n// after\n@DefaultLocale(localeProvider = MyProvider.class)\nvoid test() {}","handlingStrategy":"validation","validationCode":"if (annotation.localeProvider() != NullLocaleProvider.class\n        && (!annotation.country().isEmpty() || !annotation.variant().isEmpty())) {\n    // conflict: remove country/variant\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["A LocaleProvider must be the sole source of the locale.","Clear country/variant/language/value when using a provider.","Encode the locale decision inside the provider, not the annotation."],"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"}