{"record":{"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/f070c699a08b5d8393df9afd147af5c5e90bb21b/junit-jupiter-api/src/main/java/org/junit/jupiter/api/util/DefaultTimeZoneExtension.java#L55-L91","documentation":"ExtensionConfigurationException from DefaultTimeZoneExtension.validateCorrectConfiguration, raised when @DefaultTimeZone specifies neither a time-zone id (value empty) nor a timeZoneProvider (still the NullTimeZoneProvider default) — or specifies both. Exactly one of value or provider must be set.","triggerScenarios":"Annotating a test with @DefaultTimeZone (no attributes), or @DefaultTimeZone(value = \"UTC\", timeZoneProvider = MyProvider.class). The guard `noValue == noProvider` is true when both are absent or both are present.","commonSituations":"Adding @DefaultTimeZone as a marker expecting a default; specifying both a literal id and a provider 'just in case'; refactoring from one form to the other and leaving both populated.","solutions":["Set exactly one: either value = \"UTC\" (a zone id) or timeZoneProvider = MyProvider.class.","Remove the unused attribute so only one source of the TimeZone remains."],"exampleFix":"// before\n@DefaultTimeZone(value = \"UTC\", timeZoneProvider = MyProvider.class)\nvoid test() {}\n// after\n@DefaultTimeZone(\"UTC\")\nvoid test() {}","handlingStrategy":"validation","validationCode":"boolean noValue = annotation.value().isEmpty();\nboolean noProvider = annotation.timeZoneProvider() == NullTimeZoneProvider.class;\nif (noValue == noProvider) { /* must set exactly one */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set exactly one of value or timeZoneProvider on @DefaultTimeZone.","Remove the other attribute when switching forms.","Remember the default NullTimeZoneProvider counts as 'unset'."],"tags":["default-timezone","extension-config","mutual-exclusion","annotation-misuse"],"backgroundTag":null,"analyzedSha":"f070c699a08b5d8393df9afd147af5c5e90bb21b","analyzedAt":"2026-08-11T20:31:00.530Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}