junit-team/junit5 · error · ExtensionConfigurationException
@DefaultLocale can only be used with a provider if value…
Error message
@DefaultLocale can only be used with a provider if value, language, country and variant are not set.
What it means
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.
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.
Example fix
// before
@DefaultLocale(localeProvider = MyProvider.class, country = "US")
void test() {}
// after
@DefaultLocale(localeProvider = MyProvider.class)
void test() {} Defensive patterns
Strategy: validation
Validate before calling
if (annotation.localeProvider() != NullLocaleProvider.class
&& (!annotation.country().isEmpty() || !annotation.variant().isEmpty())) {
// conflict: remove country/variant
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Adding a provider while leaving previously-set country/variant attributes in place; misunderstanding that the provider fully determines the locale.
Related errors
- @DefaultLocale can only be used with language tag if…
- @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/eedcce7995afef20.
Report an issue: GitHub.
Appendix: source
Thrown at junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java:104
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.");
}
}
private static Locale getFromProvider(DefaultLocale annotation) {
if (!annotation.country().isEmpty() || !annotation.variant().isEmpty())
throw new ExtensionConfigurationException(
"@DefaultLocale can only be used with a provider if value, language, country and variant are not set.");
var providerClass = annotation.localeProvider();
LocaleProvider provider;
try {
provider = ReflectionSupport.newInstance(providerClass);
}
catch (Exception exception) {
throw new ExtensionConfigurationException(
"LocaleProvider instance could not be constructed because of an exception", exception);
}
return invoke(provider);
}
@SuppressWarnings("ConstantValue")
private static Locale invoke(LocaleProvider provider) {
var locale = provider.get();
if (locale == null) {
throw new ExtensionConfigurationException("LocaleProvider instance returned with null");View on GitHub (pinned to f070c699a0)