{"record":{"id":"c7cd6182018f71b8","repo":"apache/pulsar","slug":"invalid-string-to-parse-workerinfo-str","errorCode":null,"errorMessage":"Invalid string to parse WorkerInfo : ${str}","messagePattern":"Invalid string to parse WorkerInfo : (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-admin-api/src/main/java/org/apache/pulsar/common/functions/WorkerInfo.java","lineNumber":48,"sourceCode":" */\n@Getter\n@AllArgsConstructor(access = AccessLevel.PRIVATE)\n@NoArgsConstructor\n@ToString\n@CustomLog\npublic class WorkerInfo {\n    private String workerId;\n    private String workerHostname;\n    private int port;\n\n    public static WorkerInfo of(String workerId, String workerHostname, int port) {\n        return new WorkerInfo(workerId, workerHostname, port);\n    }\n\n    public static WorkerInfo parseFrom(String str) {\n        String[] tokens = str.split(\":\");\n        if (tokens.length != 3) {\n            throw new IllegalArgumentException(\"Invalid string to parse WorkerInfo : \" + str);\n        }\n\n        String workerId = tokens[0];\n        String workerHostname = tokens[1];\n        try {\n            int port = Integer.parseInt(tokens[2]);\n\n            return new WorkerInfo(workerId, workerHostname, port);\n        } catch (NumberFormatException nfe) {\n            log.warn().attr(\"workerInfo\", str).log(\"Invalid worker info\");\n            throw nfe;\n        }\n    }\n}\n","sourceCodeStart":30,"sourceCodeEnd":63,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-admin-api/src/main/java/org/apache/pulsar/common/functions/WorkerInfo.java#L30-L63","documentation":"WorkerInfo.parseFrom splits a 'workerId:hostname:port' string on ':' and throws IllegalArgumentException if the string does not have exactly 3 tokens. It is a strict format parser for worker identification strings used by the functions worker metadata.","triggerScenarios":"Calling WorkerInfo.parseFrom(str) with a string that doesn't contain exactly two ':' separators, e.g. an empty string, a hostname containing ':' (IPv6), or a malformed/legacy serialization.","commonSituations":"Storing worker info in config files or ZooKeeper metadata with a wrong format, IPv6 hostnames adding extra colons, copy-paste errors with whitespace, or reading a value written by a different serialization format.","solutions":["Ensure the input string is exactly workerId:hostname:port with no extra or missing colons","Pre-validate with str.split(\":\").length == 3 before calling parseFrom","For IPv6 hosts, use a bracketed form or a different serialization that avoids ':' ambiguity","If reading stored metadata, check which component/version wrote it and re-serialize in the expected format"],"exampleFix":"// before\nWorkerInfo info = WorkerInfo.parseFrom(config.getWorkerString());\n// after\nString s = config.getWorkerString();\nif (s == null || s.split(\":\").length != 3) {\n    throw new IllegalArgumentException(\"Expected workerId:hostname:port, got: \" + s);\n}\nWorkerInfo info = WorkerInfo.parseFrom(s);","handlingStrategy":"validation","validationCode":"boolean isParseableWorkerInfo(String s) {\n    return s != null && s.split(\":\", -1).length == 3;\n}","typeGuard":null,"tryCatchPattern":"try {\n    WorkerInfo info = WorkerInfo.parseFrom(str);\n} catch (IllegalArgumentException e) {\n    logger.error(\"Bad WorkerInfo string '{}': {}\", str, e.getMessage());\n}","preventionTips":["Always serialize with WorkerInfo's own toString/format, never hand-concatenate","Beware IPv6 hostnames containing ':'","Trim and validate stored metadata strings after upgrades"],"tags":["parsing","illegal-argument","format"],"backgroundTag":"invalid-format-string","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"}