{"id":"3a1991fa54f4e45e","repo":"junit-team/junit5","slug":"could-not-map-timeunit-unit-to-chronounit","errorCode":null,"errorMessage":"Could not map TimeUnit <unit> to ChronoUnit","messagePattern":"Could not map TimeUnit <unit> to ChronoUnit","errorType":"exception","errorClass":"JUnitException","httpStatus":null,"severity":"error","filePath":"junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutDuration.java","lineNumber":59,"sourceCode":"\t\t\tlabel = label.substring(0, label.length() - 1);\n\t\t}\n\t\treturn value + \" \" + label;\n\t}\n\n\tpublic Duration toDuration() {\n\t\treturn Duration.of(value, toChronoUnit());\n\t}\n\n\tprivate ChronoUnit toChronoUnit() {\n\t\treturn switch (unit) {\n\t\t\tcase NANOSECONDS -> ChronoUnit.NANOS;\n\t\t\tcase MICROSECONDS -> ChronoUnit.MICROS;\n\t\t\tcase MILLISECONDS -> ChronoUnit.MILLIS;\n\t\t\tcase SECONDS -> ChronoUnit.SECONDS;\n\t\t\tcase MINUTES -> ChronoUnit.MINUTES;\n\t\t\tcase HOURS -> ChronoUnit.HOURS;\n\t\t\tcase DAYS -> ChronoUnit.DAYS;\n\t\t\tdefault -> throw new JUnitException(\"Could not map TimeUnit \" + unit + \" to ChronoUnit\");\n\t\t};\n\t}\n}\n","sourceCodeStart":41,"sourceCodeEnd":63,"githubUrl":"https://github.com/junit-team/junit5/blob/956246301e03d757539f7b76dd5a91f298637563/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TimeoutDuration.java#L41-L63","documentation":"Thrown by TimeoutDuration.toChronoUnit() when a java.util.concurrent.TimeUnit value does not map to one of the seven handled ChronoUnit constants. TimeUnit is a final enum with exactly seven values (NANOSECONDS through DAYS) and all seven are covered by the switch, so this default branch is effectively unreachable defensive code. It exists to satisfy exhaustiveness and guard against a hypothetical future TimeUnit constant.","triggerScenarios":"Calling new TimeoutDuration(value, unit).toDuration() where 'unit' is a TimeUnit constant not covered by the seven switch cases. Since TimeUnit has exactly seven constants and all are mapped, no standard input reaches this branch.","commonSituations":"Practically never encountered by end users. Could only surface if the JDK ever added a new TimeUnit constant without updating JUnit, or via reflection-based manipulation of the enum (not a real-world scenario).","solutions":["This error should not occur under normal usage; verify you are using a stock JDK and standard TimeUnit values","If it does appear, file a bug against junit-jupiter-engine since the switch is missing a TimeUnit mapping"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// TimeUnit is a fixed enum with exactly 7 values (NANOSECONDS..DAYS).\n// No user validation is needed — all values are mapped.\n// This branch is unreachable defensive code.\nboolean isSupported = EnumSet.allOf(TimeUnit.class).contains(unit);\n// Always true for any TimeUnit constant.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["No prevention needed — this error is unreachable with standard JDK TimeUnit values","Report it as a JUnit bug if it ever appears, as it indicates a missing switch case"],"tags":["timeout","internal-assertion","unreachable","junit-jupiter-engine"],"analyzedSha":"956246301e03d757539f7b76dd5a91f298637563","analyzedAt":"2026-08-04T19:25:17.049Z","schemaVersion":2}