junit-team/junit5 · error · ExtensionConfigurationException
@DefaultLocale can only be used with a provider if value, la
Error message
@DefaultLocale can only be used with a provider if value, language, country and variant are not set.
What it means
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.
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 956246301e)
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=.
Example fix
// before
@DefaultLocale(country = "US", localeProvider = MyLocaleProvider.class)
void test() {}
// after — provider mode is exclusive
@DefaultLocale(localeProvider = MyLocaleProvider.class)
void test() {} Defensive patterns
Strategy: validation
Validate before calling
DefaultLocale d = testClass.getAnnotation(DefaultLocale.class);
boolean providerMode = d.value().isEmpty() && d.language().isEmpty();
boolean providerSet = d.localeProvider() != NullLocaleProvider.class;
if (providerMode && providerSet && (!d.country().isEmpty() || !d.variant().isEmpty())) {
throw new IllegalStateException("@DefaultLocale provider cannot be combined with country= or variant=");
} Prevention
- When using localeProvider=, leave value=, language=, country=, and variant= all unset.
- Audit annotations after switching configuration modes.
When it happens
Trigger: Annotating a test with @DefaultLocale(country = "US", localeProvider = MyProvider.class) or @DefaultLocale(variant = "POSIX", localeProvider = MyProvider.class) without setting value or language.
Common situations: Trying to 'augment' a provider-supplied Locale with extra parts; partial migration where country= was left behind when switching to provider mode.
Related errors
- @DefaultLocale can only be used with language tag if languag
- @DefaultLocale can only be used with language tag if provide
- @DefaultLocale not configured correctly. When not using a la
- LocaleProvider instance could not be constructed because of
- LocaleProvider instance returned with null
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/eedcce7995afef20.json.
Report an issue: GitHub.