junit-team/junit5 · error · ExtensionConfigurationException

@DefaultTimeZone not configured correctly. Could not find th

Error message

@DefaultTimeZone not configured correctly.
Could not find the specified time zone + '%s'.
Please use correct identifiers, e.g. "GMT" for Greenwich Mean Time.

What it means

Thrown as ExtensionConfigurationException by DefaultTimeZoneExtension.createTimeZoneFromZoneId when the supplied zone id does not resolve to a known TimeZone. java.util.TimeZone.getTimeZone silently falls back to GMT for unknown ids, so JUnit explicitly checks: if the result equals GMT but the input was not literally "GMT", the id is invalid and the extension refuses to silently use GMT.

Source

Thrown at junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultTimeZoneExtension.java:83

			return createTimeZoneFromProvider(annotation.timeZoneProvider());
		}
	}

	private static void validateCorrectConfiguration(DefaultTimeZone annotation) {
		boolean noValue = annotation.value().isEmpty();
		boolean noProvider = annotation.timeZoneProvider() == NullTimeZoneProvider.class;
		if (noValue == noProvider) {
			throw new ExtensionConfigurationException(
				"Either a valid time zone id or a TimeZoneProvider must be provided to "
						+ DefaultTimeZone.class.getSimpleName());
		}
	}

	private static TimeZone createTimeZoneFromZoneId(String timeZoneId) {
		TimeZone configuredTimeZone = TimeZone.getTimeZone(timeZoneId);
		// TimeZone::getTimeZone returns with GMT as fallback if the given ID cannot be understood
		if (configuredTimeZone.equals(TimeZone.getTimeZone("GMT")) && !"GMT".equals(timeZoneId)) {
			throw new ExtensionConfigurationException("""
					@DefaultTimeZone not configured correctly.
					Could not find the specified time zone + '%s'.
					Please use correct identifiers, e.g. "GMT" for Greenwich Mean Time.
					""".formatted(timeZoneId));
		}
		return configuredTimeZone;
	}

	private static TimeZone createTimeZoneFromProvider(Class<? extends TimeZoneProvider> providerClass) {
		try {
			TimeZoneProvider provider = ReflectionSupport.newInstance(providerClass);
			return Optional.ofNullable(provider.get()).orElse(TimeZone.getTimeZone("GMT"));
		}
		catch (Exception exception) {
			throw new ExtensionConfigurationException("Could not instantiate TimeZoneProvider because of exception",
				exception);
		}
	}

View on GitHub (pinned to 956246301e)

Solutions

  1. Use a valid IANA time zone id, e.g. @DefaultTimeZone(value = "America/Los_Angeles") or @DefaultTimeZone(value = "GMT").
  2. Confirm the id via java.util.TimeZone.getAvailableIDs() or ZoneId.of(id) before using it.
  3. If you genuinely need GMT, set value = "GMT" exactly (that is whitelisted).

Example fix

// before
@DefaultTimeZone(value = "Pacific Standard Time") // not an IANA id -> falls back to GMT
void test() {}

// after
@DefaultTimeZone(value = "America/Los_Angeles")
void test() {}
Defensive patterns

Strategy: validation

Validate before calling

String id = "America/Los_Angeles"; // the value you plan to use
if (!java.util.Arrays.asList(java.util.TimeZone.getAvailableIDs()).contains(id)
        && java.time.ZoneId.of(id) == null) {
    throw new IllegalArgumentException("unknown time zone id: " + id);
}
// extra guard against the GMT-fallback silent failure:
java.util.TimeZone tz = java.util.TimeZone.getTimeZone(id);
if (tz.equals(java.util.TimeZone.getTimeZone("GMT")) && !"GMT".equals(id)) {
    throw new IllegalArgumentException("time zone id falls back to GMT: " + id);
}

Prevention

When it happens

Trigger: Annotating with @DefaultTimeZone(value = "ZZZ"), a typo such as @DefaultTimeZone(value = "GM"), a non-IANF id, or any string TimeZone.getTimeZone does not recognize. Note that some custom ids (e.g. "PST") ARE recognized; the failure is specifically for ids that fall through to the GMT fallback.

Common situations: Using a non-IANA zone id (e.g., a JVM-display name like 'Pacific Standard Time' instead of 'America/Los_Angeles'); typos; assuming a three-letter abbreviation that TimeZone does not honor.

Related errors


AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04). Data as JSON: /data/errors/2cdf42c211c54ef0.json. Report an issue: GitHub.