junit-team/junit5 · error · ExtensionConfigurationException
@DefaultLocale not configured correctly. When not using a la
Error message
@DefaultLocale not configured correctly. When not using a language tag, specify either language, or language and country, or language and country and variant.
What it means
Thrown as ExtensionConfigurationException by DefaultLocaleExtension.createFromParts when parts-based @DefaultLocale configuration is internally inconsistent: language is set but country is empty and variant is non-empty. The only valid parts-based shapes are language alone, language+country, or language+country+variant — variant without country is not a legal Locale.
Source
Thrown at junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultLocaleExtension.java:96
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.");
}
}
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);
}View on GitHub (pinned to 956246301e)
Solutions
- Add the missing country attribute: @DefaultLocale(language = "en", country = "US", variant = "POSIX").
- If you did not intend a variant, remove variant= and use language alone or language+country.
- Prefer the BCP-47 tag form @DefaultLocale(value = "en-US-POSIX") which lets Locale.forLanguageTag normalize the parts.
Example fix
// before
@DefaultLocale(language = "en", variant = "POSIX")
void test() {}
// after — variant requires a country
@DefaultLocale(language = "en", country = "US", variant = "POSIX")
void test() {} Defensive patterns
Strategy: validation
Validate before calling
DefaultLocale d = testClass.getAnnotation(DefaultLocale.class);
boolean l = !d.language().isEmpty(), c = !d.country().isEmpty(), v = !d.variant().isEmpty();
boolean validParts = l || c || v
? (l && !v) || (l && c) // language alone, language+country[+variant]
: true;
if (!validParts) {
throw new IllegalStateException("@DefaultLocale parts require language, and variant requires country");
} Prevention
- Variant requires country; country requires language. The only valid stacks are L, L+C, L+C+V.
- Prefer @DefaultLocale(value = "en-US-POSIX") to let the JVM normalize parts for you.
- Double-check trimmed-down @DefaultLocale annotations to ensure no orphan variant= or country=.
When it happens
Trigger: Annotating a test with @DefaultLocale(language = "en", variant = "POSIX") (no country). Also reached if country is somehow empty while variant is set, regardless of which attribute the developer thought they were configuring.
Common situations: Misunderstanding the Locale(language, country, variant) constructor contract (variant requires country); trimming a @DefaultLocale down and accidentally removing country= but leaving variant=.
Related errors
- @DefaultLocale can only be used with language tag if languag
- @DefaultLocale can only be used with language tag if provide
- @DefaultLocale can only be used with a provider if value, 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/933d2eb922832bed.json.
Report an issue: GitHub.