{"record":{"id":"88cc3d2ccb8c5777","repo":"junit-team/junit5","slug":"defaultlocale-can-only-be-used-with-language-tag-88cc3d","errorCode":null,"errorMessage":"@DefaultLocale can only be used with language tag if provider is not set","messagePattern":"@DefaultLocale can only be used with language tag if provider is 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":81,"sourceCode":"\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}\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}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/junit-team/junit5/blob/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java#L63-L99","documentation":"ExtensionConfigurationException from DefaultLocaleExtension.createFromParts, raised when @DefaultLocale is configured with language (and possibly country/variant) parts AND a custom localeProvider at the same time. Parts-based construction and a LocaleProvider are mutually exclusive.","triggerScenarios":"Annotating a test with @DefaultLocale(language = \"en\", localeProvider = MyProvider.class). createFromParts is chosen when value() is empty but language is non-empty; it rejects any non-default provider.","commonSituations":"Switching from a provider-based to a parts-based configuration but forgetting to reset localeProvider back to the default NullLocaleProvider; merging two annotation usages during refactor.","solutions":["Drop the localeProvider attribute (it defaults to NullLocaleProvider) when using language/country/variant.","OR keep the provider and remove language/country/variant so getFromProvider is used instead."],"exampleFix":"// before\n@DefaultLocale(language = \"en\", localeProvider = MyProvider.class)\nvoid test() {}\n// after\n@DefaultLocale(language = \"en\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"if (!annotation.language().isEmpty() && annotation.localeProvider() != NullLocaleProvider.class) {\n    // conflict: remove provider or remove parts\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Parts and provider are mutually exclusive in @DefaultLocale.","Reset localeProvider to default when using language/country/variant.","Validate annotation shape in a shared helper before tests run."],"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"}