{"id":"90d177863e6bcac2","repo":"junit-team/junit5","slug":"either-a-valid-time-zone-id-or-a-timezoneprovider","errorCode":null,"errorMessage":"Either a valid time zone id or a TimeZoneProvider must be provided to DefaultTimeZone","messagePattern":"Either a valid time zone id or a TimeZoneProvider must be provided to DefaultTimeZone","errorType":"exception","errorClass":"ExtensionConfigurationException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultTimeZoneExtension.java","lineNumber":73,"sourceCode":"\t\t\t\t.map(DefaultTimeZoneExtension::createTimeZone);\n\t}\n\n\tprivate static TimeZone createTimeZone(DefaultTimeZone annotation) {\n\t\tvalidateCorrectConfiguration(annotation);\n\n\t\tif (!annotation.value().isEmpty()) {\n\t\t\treturn createTimeZoneFromZoneId(annotation.value());\n\t\t}\n\t\telse {\n\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","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultTimeZoneExtension.java#L55-L91","documentation":"Thrown as ExtensionConfigurationException by DefaultTimeZoneExtension.validateCorrectConfiguration when @DefaultTimeZone is misconfigured: EITHER both 'value' (zone id) is empty AND timeZoneProvider is the default NullTimeZoneProvider (neither supplied), OR both value and a non-default provider are supplied (both supplied). Exactly one of value= or timeZoneProvider= must be set.","triggerScenarios":"An empty @DefaultTimeZone() with no attributes; or @DefaultTimeZone(value = \"GMT\", timeZoneProvider = MyProvider.class) supplying both at once.","commonSituations":"Forgetting to fill in either attribute; copy-pasting an annotation and adding value= on top of an existing provider=; misunderstanding that the two are mutually exclusive sources of the TimeZone.","solutions":["Set exactly one: @DefaultTimeZone(value = \"GMT\") OR @DefaultTimeZone(timeZoneProvider = MyProvider.class).","If you do not need a custom time zone at all, remove the @DefaultTimeZone annotation entirely.","Double-check that an IDE-generated annotation stub did not leave both attributes blank."],"exampleFix":"// before\n@DefaultTimeZone(value = \"GMT\", timeZoneProvider = MyTimeZoneProvider.class)\nvoid test() {}\n\n// after — pick one source\n@DefaultTimeZone(value = \"GMT\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"DefaultTimeZone tz = testClass.getAnnotation(DefaultTimeZone.class);\nboolean hasValue = !tz.value().isEmpty();\nboolean hasProvider = tz.timeZoneProvider() != NullTimeZoneProvider.class;\nif (hasValue == hasProvider) { // both set or both unset\n    throw new IllegalStateException(\"@DefaultTimeZone requires exactly one of value= or timeZoneProvider=\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set exactly one of value= or timeZoneProvider= on @DefaultTimeZone.","Remove @DefaultTimeZone entirely if no custom time zone is needed.","Watch for IDE auto-completion inserting empty annotation stubs."],"tags":["default-timezone","extension-configuration","annotation-misuse","junit-jupiter"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}