junit-team/junit5 · error · ExtensionConfigurationException
@DefaultLocale can only be used with language tag if…
Error message
@DefaultLocale can only be used with language tag if provider is not set
What it means
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.
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.
Example fix
// before
@DefaultLocale(language = "en", localeProvider = MyProvider.class)
void test() {}
// after
@DefaultLocale(language = "en")
void test() {} Defensive patterns
Strategy: validation
Validate before calling
if (!annotation.language().isEmpty() && annotation.localeProvider() != NullLocaleProvider.class) {
// conflict: remove provider or remove parts
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- @DefaultLocale can only be used with a provider if value…
- @DefaultLocale can only be used with language tag if…
- @DefaultLocale not configured correctly. When not using a…
- Either a valid time zone id or a TimeZoneProvider must be…
- LocaleProvider instance could not be constructed because of…
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/88cc3d2ccb8c5777.
Report an issue: GitHub.
Appendix: source
Thrown at junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java:81
return createFromParts(annotation);
}
else {
return getFromProvider(annotation);
}
}
private static Locale createFromLanguageTag(DefaultLocale annotation) {
if (!annotation.language().isEmpty() || !annotation.country().isEmpty() || !annotation.variant().isEmpty()
|| annotation.localeProvider() != NullLocaleProvider.class) {
throw new ExtensionConfigurationException(
"@DefaultLocale can only be used with language tag if language, country, variant and provider are not set");
}
return Locale.forLanguageTag(annotation.value());
}
private static Locale createFromParts(DefaultLocale annotation) {
if (annotation.localeProvider() != NullLocaleProvider.class)
throw new ExtensionConfigurationException(
"@DefaultLocale can only be used with language tag if provider is not set");
String language = annotation.language();
String country = annotation.country();
String variant = annotation.variant();
if (!language.isEmpty() && !country.isEmpty() && !variant.isEmpty()) {
return JupiterLocaleUtils.createLocale(language, country, variant);
}
else if (!language.isEmpty() && !country.isEmpty()) {
return JupiterLocaleUtils.createLocale(language, country);
}
else if (!language.isEmpty() && variant.isEmpty()) {
return JupiterLocaleUtils.createLocale(language);
}
else {
throw new ExtensionConfigurationException(
"@DefaultLocale not configured correctly. When not using a language tag, specify either"
+ " language, or language and country, or language and country and variant.");
}View on GitHub (pinned to f070c699a0)