{"record":{"id":"c7313577d72620d8","repo":"apache/pulsar","slug":"invalid-hostname-hostname","errorCode":null,"errorMessage":"Invalid hostname : ${hostname}","messagePattern":"Invalid hostname : (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-common/src/main/java/org/apache/pulsar/common/net/ServiceURI.java","lineNumber":176,"sourceCode":"            \"service path component is missing in service uri : \" + uri);\n\n        return new ServiceURI(\n            serviceName,\n            serviceInfos,\n            serviceUser,\n            serviceHosts.toArray(new String[serviceHosts.size()]),\n            servicePath,\n            uri);\n    }\n\n    private static String validateHostName(String serviceName,\n                                           String[] serviceInfos,\n                                           String hostname) {\n        URI uri = null;\n        try {\n            uri = URI.create(\"dummyscheme://\" + hostname);\n        } catch (IllegalArgumentException e) {\n            throw new IllegalArgumentException(\"Invalid hostname : \" + hostname);\n        }\n        String host = uri.getHost();\n        if (host == null) {\n            throw new IllegalArgumentException(\"Invalid hostname : \" + hostname);\n        }\n        int port = uri.getPort();\n        if (port == -1) {\n            port = getServicePort(serviceName, serviceInfos);\n        }\n        return host + \":\" + port;\n    }\n\n    private final String serviceName;\n    private final String[] serviceInfos;\n    private final String serviceUser;\n    private final String[] serviceHosts;\n    private final String servicePath;\n    private final URI uri;","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-common/src/main/java/org/apache/pulsar/common/net/ServiceURI.java#L158-L194","documentation":"ServiceURI.create validates each host part by parsing 'dummyscheme://<hostname>' with java.net.URI. If URI.create itself throws IllegalArgumentException (malformed URI syntax) the hostname is rejected with 'Invalid hostname : <hostname>'. This means the string between ':' separators is not a syntactically valid host.","triggerScenarios":"Calling ServiceURI.create('pulsar://<bad-host>:6650') where the host part contains characters illegal in a URI authority — spaces, underscores, unbracketed IPv6 like '::1', multiple colons, empty host segments like 'pulsar://:6650'.","commonSituations":"Pasting a serviceUrl with a typo (space or underscore in hostname); using an unbracketed IPv6 address; building the URI by string concatenation with an unresolved/empty host variable.","solutions":["Fix the hostname in the serviceUrl: remove illegal characters (spaces, underscores) and percent-encode if needed.","Bracket IPv6 addresses: pulsar://[fe80::1]:6650 instead of pulsar://fe80::1:6650.","Ensure the host segment is non-empty between scheme:// and :port.","Validate the host before calling ServiceURI.create (see validationCode)."],"exampleFix":"// before\nServiceURI u = ServiceURI.create(\"pulsar://my_broker:6650\");\n// after\nServiceURI u = ServiceURI.create(\"pulsar://my-broker.example.com:6650\");\n// or for IPv6\nServiceURI u = ServiceURI.create(\"pulsar://[2001:db8::1]:6650\");","handlingStrategy":"validation","validationCode":"static void assertValidHost(String host) {\n    URI u = URI.create(\"dummyscheme://\" + host); // throws IllegalArgumentException\n    if (u.getHost() == null) {\n        throw new IllegalArgumentException(\"Invalid hostname : \" + host);\n    }\n}\n// call assertValidHost(host) before ServiceURI.create(...)","typeGuard":"static boolean isParsableHost(String host) {\n    try {\n        return URI.create(\"dummyscheme://\" + host).getHost() != null;\n    } catch (IllegalArgumentException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    ServiceURI uri = ServiceURI.create(serviceUrl);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Invalid hostname\")) {\n        // fix hostname: no spaces/underscores; bracket IPv6 like [fe80::1]\n    }\n    throw e;\n}","preventionTips":["Bracket IPv6 addresses in service URLs.","Never put spaces or underscores in hostnames.","Build serviceUrls from variables defensively; fail fast on empty host values.","Validate hostnames with the dummyscheme trick before constructing ServiceURI."],"tags":["uri","hostname","config"],"backgroundTag":"invalid-hostname","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"}