junit-team/junit5 · error · ExtensionConfigurationException
@DefaultTimeZone not configured correctly. Could not find…
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
ExtensionConfigurationException from DefaultTimeZoneExtension.createTimeZoneFromZoneId, thrown when the supplied zone id is unrecognized. Because TimeZone.getTimeZone silently falls back to GMT for unknown ids, JUnit explicitly checks: if the resolved zone equals GMT but the requested id was not literally "GMT", the id is treated as invalid and rejected.
Solutions
- Use a valid IANA zone id, e.g. "America/New_York", "Europe/Berlin", "UTC".
- Confirm the id via java.time.ZoneId.getAvailableZoneIds() if unsure.
- Avoid deprecated three-letter ids; prefer the canonical IANA names.
Example fix
// before
@DefaultTimeZone("EST")
void test() {}
// after
@DefaultTimeZone("America/New_York")
void test() {} Defensive patterns
Strategy: validation
Validate before calling
String id = annotation.value();
if (!ZoneId.getAvailableZoneIds().contains(id)) { /* not a valid IANA id */ } Type guard
static boolean isValidZoneId(String id) {
return ZoneId.getAvailableZoneIds().contains(id);
} Prevention
- Use canonical IANA zone ids (e.g. America/New_York, Europe/Berlin, UTC).
- Avoid deprecated three-letter ids (EST, PST).
- Cross-check with java.time.ZoneId.getAvailableZoneIds() when unsure.
When it happens
Trigger: Annotating with @DefaultTimeZone("US/Eastern") (Java uses "America/New_York" — wrong id), or a typo like @DefaultTimeZone("UTSC"), or any string TimeZone.getTimeZone cannot map. The equals-GMT-but-not-GMT branch fires.
Common situations: Using the legacy three-letter ids ("EST", "PST") which are deprecated/ambiguous; typos; copying an IANA id that the JVM's tz database doesn't have; regional shorthand that isn't a real zone.
Related errors
- Could not instantiate TimeZoneProvider because of exception
- Either a valid time zone id or a TimeZoneProvider must be…
- @DefaultLocale can only be used with a provider if value…
- @DefaultLocale can only be used with language tag if…
- @DefaultLocale can only be used with language tag if…
AI-assisted analysis of junit-team/junit5@f070c699a0 (2026-08-11).
Data as JSON: /api/errors/2cdf42c211c54ef0.
Report an issue: GitHub.
Appendix: 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 f070c699a0)