{"record":{"id":"fcfbd2c155f73cfe","repo":"apache/pulsar","slug":"invalid-time-unit-lastchar","errorCode":null,"errorMessage":"Invalid time unit '${lastChar}'","messagePattern":"Invalid time unit '(.+?)'","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/RelativeTimeUtil.java","lineNumber":62,"sourceCode":"\n        long duration = Long.parseLong(relativeTime.substring(0, lastIndex));\n\n        switch (timeUnit) {\n        case 's':\n            return duration;\n        case 'm':\n            return TimeUnit.MINUTES.toSeconds(duration);\n        case 'h':\n            return TimeUnit.HOURS.toSeconds(duration);\n        case 'd':\n            return TimeUnit.DAYS.toSeconds(duration);\n        case 'w':\n            return 7 * TimeUnit.DAYS.toSeconds(duration);\n        // No unit for months\n        case 'y':\n            return 365 * TimeUnit.DAYS.toSeconds(duration);\n        default:\n            throw new IllegalArgumentException(\"Invalid time unit '\" + lastChar + \"'\");\n        }\n    }\n\n    /**\n     * Convert nanoseconds to seconds and keep three decimal places.\n     * @param ns\n     * @return seconds\n     */\n    public static double nsToSeconds(long ns) {\n        double seconds = (double) ns / 1_000_000_000;\n        BigDecimal bd = new BigDecimal(seconds);\n        return bd.setScale(3, RoundingMode.HALF_UP).doubleValue();\n    }\n}\n","sourceCodeStart":44,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/RelativeTimeUtil.java#L44-L77","documentation":"Unit-switch default in RelativeTimeUtil.parseRelativeTimeInSeconds: the parsed duration's last character is not one of s/m/h/d/w/y, so the switch falls to the default branch and rejects the string; the trailing unit character of the relativeTime argument is the faulty input.","triggerScenarios":"Thrown at pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/RelativeTimeUtil.java:62 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a supported unit suffix: s, m, h, d, w, or y (no months)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}