{"record":{"id":"7716adc73c1835a0","repo":"brettwooldridge/HikariCP","slug":"could-not-match-unit-got-s-from-given-value-s","errorCode":null,"errorMessage":"Could not match unit, got %s (from given value %s)","messagePattern":"Could not match unit, got (.+?) \\(from given value (.+?)\\)","errorType":"validation","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/zaxxer/hikari/util/PropertyElf.java","lineNumber":264,"sourceCode":"   private static Optional<Duration> parseDuration(String value)\n   {\n      var matcher = DURATION_PATTERN.matcher(value);\n      if (matcher.matches()) {\n         var number = Long.parseLong(matcher.group(\"number\"));\n         var unit = matcher.group(\"unit\");\n         switch (unit) {\n            case \"ms\":\n               return Optional.of(Duration.ofMillis(number));\n            case \"s\":\n               return Optional.of(Duration.ofSeconds(number));\n            case \"m\":\n               return Optional.of(Duration.ofMinutes(number));\n            case \"h\":\n               return Optional.of(Duration.ofHours(number));\n            case \"d\":\n               return Optional.of(Duration.ofDays(number));\n            default:\n               throw new IllegalStateException(String.format(\"Could not match unit, got %s (from given value %s)\", unit, value));\n         }\n      } else {\n         return Optional.empty();\n      }\n   }\n}\n","sourceCodeStart":246,"sourceCodeEnd":271,"githubUrl":"https://github.com/brettwooldridge/HikariCP/blob/a4d93f4f85517f90e632b795486d7102e933d7ff/src/main/java/com/zaxxer/hikari/util/PropertyElf.java#L246-L271","documentation":"PropertyElf.parseDuration accepts a number plus a unit suffix of ms, s, m, h, or d when setting duration-typed properties (connectionTimeout etc. also accept long millis). Any other unit suffix makes the switch hit default and throw IllegalStateException naming the bad unit and value.","triggerScenarios":"Writing connectionTimeout=30sec, minimumIdle=10min, maxLifetime=1hour or 500us; locale-specific input like '30 s' with a space; copy-pasting durations from other tools that support units HikariCP does not.","commonSituations":"Config authored against Micrometer/ Dropwizard duration syntax (supports ns/us), documentation confusion, machine-generated config emitting unsupported units.","solutions":["Use only supported suffixes: ms, s, m, h, d (e.g. connectionTimeout=3000ms or 3s)","Or supply plain milliseconds as a number (legacy format)","Fix generated config templates that emit ns/us/sec/min suffixes"],"exampleFix":"# before\nconnectionTimeout=30sec\nmaxLifetime=30min\n\n# after\nconnectionTimeout=30s\nmaxLifetime=30m","handlingStrategy":"validation","validationCode":"static final Set<String> UNITS = Set.of(\"ms\",\"s\",\"m\",\"h\",\"d\");\nstatic boolean validDuration(String v) {\n    var m = Pattern.compile(\"(\\\\d+)(\\\\w*)\").matcher(v);\n    return m.matches() && (m.group(2).isEmpty() || UNITS.contains(m.group(2)));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use only ms/s/m/h/d suffixes (or bare millis)","Lint config files for duration syntax","Do not copy duration strings from tools with ns/us support"],"tags":["hikaricp","configuration","duration","parsing"],"backgroundTag":null,"analyzedSha":"a4d93f4f85517f90e632b795486d7102e933d7ff","analyzedAt":"2026-08-14T12:11:37.292Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}