{"id":"2cdf42c211c54ef0","repo":"junit-team/junit5","slug":"defaulttimezone-not-configured-correctly-could-n","errorCode":null,"errorMessage":"@DefaultTimeZone not configured correctly.\nCould not find the specified time zone + '%s'.\nPlease use correct identifiers, e.g. \"GMT\" for Greenwich Mean Time.","messagePattern":"@DefaultTimeZone not configured correctly\\.\nCould not find the specified time zone \\+ '(.+?)'\\.\nPlease use correct identifiers, e\\.g\\. \"GMT\" for Greenwich Mean Time\\.","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultTimeZoneExtension.java","lineNumber":83,"sourceCode":"\t\t\treturn createTimeZoneFromProvider(annotation.timeZoneProvider());\n\t\t}\n\t}\n\n\tprivate static void validateCorrectConfiguration(DefaultTimeZone annotation) {\n\t\tboolean noValue = annotation.value().isEmpty();\n\t\tboolean noProvider = annotation.timeZoneProvider() == NullTimeZoneProvider.class;\n\t\tif (noValue == noProvider) {\n\t\t\tthrow new ExtensionConfigurationException(\n\t\t\t\t\"Either a valid time zone id or a TimeZoneProvider must be provided to \"\n\t\t\t\t\t\t+ DefaultTimeZone.class.getSimpleName());\n\t\t}\n\t}\n\n\tprivate static TimeZone createTimeZoneFromZoneId(String timeZoneId) {\n\t\tTimeZone configuredTimeZone = TimeZone.getTimeZone(timeZoneId);\n\t\t// TimeZone::getTimeZone returns with GMT as fallback if the given ID cannot be understood\n\t\tif (configuredTimeZone.equals(TimeZone.getTimeZone(\"GMT\")) && !\"GMT\".equals(timeZoneId)) {\n\t\t\tthrow new ExtensionConfigurationException(\"\"\"\n\t\t\t\t\t@DefaultTimeZone not configured correctly.\n\t\t\t\t\tCould not find the specified time zone + '%s'.\n\t\t\t\t\tPlease use correct identifiers, e.g. \"GMT\" for Greenwich Mean Time.\n\t\t\t\t\t\"\"\".formatted(timeZoneId));\n\t\t}\n\t\treturn configuredTimeZone;\n\t}\n\n\tprivate static TimeZone createTimeZoneFromProvider(Class<? extends TimeZoneProvider> providerClass) {\n\t\ttry {\n\t\t\tTimeZoneProvider provider = ReflectionSupport.newInstance(providerClass);\n\t\t\treturn Optional.ofNullable(provider.get()).orElse(TimeZone.getTimeZone(\"GMT\"));\n\t\t}\n\t\tcatch (Exception exception) {\n\t\t\tthrow new ExtensionConfigurationException(\"Could not instantiate TimeZoneProvider because of exception\",\n\t\t\t\texception);\n\t\t}\n\t}","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultTimeZoneExtension.java#L65-L101","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\n@DefaultTimeZone(value = \"Pacific Standard Time\") // not an IANA id -> falls back to GMT\nvoid test() {}\n\n// after\n@DefaultTimeZone(value = \"America/Los_Angeles\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"String id = \"America/Los_Angeles\"; // the value you plan to use\nif (!java.util.Arrays.asList(java.util.TimeZone.getAvailableIDs()).contains(id)\n        && java.time.ZoneId.of(id) == null) {\n    throw new IllegalArgumentException(\"unknown time zone id: \" + id);\n}\n// extra guard against the GMT-fallback silent failure:\njava.util.TimeZone tz = java.util.TimeZone.getTimeZone(id);\nif (tz.equals(java.util.TimeZone.getTimeZone(\"GMT\")) && !\"GMT\".equals(id)) {\n    throw new IllegalArgumentException(\"time zone id falls back to GMT: \" + id);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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\"."],"tags":["default-timezone","extension-configuration","invalid-id","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}