junit-team/junit5 · error · ExtensionConfigurationException

@DefaultLocale not configured correctly. When not using a…

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

ExtensionConfigurationException from DefaultLocaleExtension.createFromParts, thrown when neither the tag form nor a valid combination of parts was supplied. Valid parts combinations are: language alone; language+country; language+country+variant. Anything else (e.g. country without language, or variant without language+country) is rejected.

Solutions

  1. Always include language when using the parts form, then add country and variant as needed.
  2. Use the value tag form (@DefaultLocale("en-US")) if you only have a region, which is simpler.
  3. Re-read the message — it lists the three valid combinations; match one exactly.

Example fix

// before
@DefaultLocale(country = "US")
void test() {}
// after
@DefaultLocale(language = "en", country = "US")
void test() {}
Defensive patterns

Strategy: validation

Validate before calling

boolean l = !annotation.language().isEmpty();
boolean c = !annotation.country().isEmpty();
boolean v = !annotation.variant().isEmpty();
boolean validParts = l && !v || l && c; // language, language+country, or all three
if (!validParts) { /* fix annotation */ }

Prevention

When it happens

Trigger: Annotating a test with @DefaultLocale(country = "US") (no language), @DefaultLocale(variant = "..."), or @DefaultLocale(language = "", country = "US", variant = "..."). None of the if/else-if branches in createFromParts match, so the final else throws.

Common situations: Assuming country alone selects a locale; typos leaving language blank; trimming an annotation down and forgetting language is mandatory.

Related errors


AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11). Data as JSON: /api/errors/933d2eb922832bed. Report an issue: GitHub.

Appendix: 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 f070c699a0)