{"record":{"id":"83fa95b8c62290e5","repo":"apache/pulsar","slug":"invalid-hash-range-format-hex","errorCode":null,"errorMessage":"Invalid hash range format: hex","messagePattern":"Invalid hash range format: hex","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/scalable/HashRange.java","lineNumber":115,"sourceCode":"    }\n\n    @Override\n    public int compareTo(HashRange o) {\n        int result = Integer.compare(start, o.start);\n        if (result == 0) {\n            result = Integer.compare(end, o.end);\n        }\n        return result;\n    }\n\n    public String toHexString() {\n        return String.format(\"%04x-%04x\", start, end);\n    }\n\n    public static HashRange fromHexString(String hex) {\n        String[] parts = hex.split(\"-\", 2);\n        if (parts.length != 2) {\n            throw new IllegalArgumentException(\"Invalid hash range format: \" + hex);\n        }\n        return new HashRange(Integer.parseInt(parts[0], 16), Integer.parseInt(parts[1], 16));\n    }\n\n    @Override\n    public String toString() {\n        return \"[\" + String.format(\"%04x\", start) + \", \" + String.format(\"%04x\", end) + \"]\";\n    }\n}\n","sourceCodeStart":97,"sourceCodeEnd":125,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/scalable/HashRange.java#L97-L125","documentation":"HashRange.fromHexString parses a range encoded as 'start-end' hex (as produced by toHexString, e.g. '00ff-01aa'). If the input has no '-' separator so split yields other than 2 parts, the string is not a valid serialized HashRange and IllegalArgumentException is thrown.","triggerScenarios":"Calling HashRange.fromHexString with a string lacking the '-' delimiter, e.g. '00ff01aa', an empty string, or a corrupted/truncated value from storage or the wire.","commonSituations":"Persisted range metadata manually edited or truncated; decoding a value produced by a different serializer or older version; off-by-one substring that dropped the hyphen.","solutions":["Pass the exact string produced by HashRange.toHexString","Validate the format matches /^[0-9a-fA-F]+-[0-9a-fA-F]+$/ before parsing","Check where the string was stored or transferred for truncation/re-encoding","Handle null/empty input before calling fromHexString"],"exampleFix":"// before\nHashRange.fromHexString(\"00ff01aa\");\n// after\nHashRange.fromHexString(\"00ff-01aa\");","handlingStrategy":"validation","validationCode":"HashRange safeParse(String hex) {\n    if (hex == null || !hex.matches(\"^[0-9a-fA-F]+-[0-9a-fA-F]+$\")) {\n        throw new IllegalArgumentException(\"Not a HashRange hex string: \" + hex);\n    }\n    return HashRange.fromHexString(hex);\n}","typeGuard":null,"tryCatchPattern":"try {\n    HashRange r = HashRange.fromHexString(s);\n} catch (IllegalArgumentException e) {\n    log.warn(\"Corrupt hash range '{}' - falling back to default\", s);\n}","preventionTips":["Always serialize with HashRange.toHexString so round-trips are symmetric","Treat parse failure of persisted range metadata as data corruption","Guard stored values against truncation; validate on load"],"tags":["serialization","parsing","hash-range","input-validation"],"backgroundTag":"invalid-serialized-format","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}