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
- Use a valid IANA time zone id, e.g. @DefaultTimeZone(value = "America/Los_Angeles") or @DefaultTimeZone(value = "GMT").
- Confirm the id via java.util.TimeZone.getAvailableIDs() or ZoneId.of(id) before using it.
- 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
- Use IANA zone ids from java.time.ZoneId.getAvailableZoneIds() (e.g. America/Los_Angeles, Europe/Berlin).
- Avoid display names like 'Pacific Standard Time'.
- If you need GMT, use the literal value = "GMT".
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
- Either a valid time zone id or a TimeZoneProvider must be pr
- Could not instantiate TimeZoneProvider because of exception
- @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
AI-assisted analysis of junit-team/junit5@956246301e (2026-08-04).
Data as JSON: /data/errors/2cdf42c211c54ef0.json.
Report an issue: GitHub.