{"record":{"id":"ea283993b0de6dce","repo":"alibaba/canal","slug":"failed-to-parse-host","errorCode":null,"errorMessage":"failed to parse host","messagePattern":"failed to parse host","errorType":"exception","errorClass":"CanalException","httpStatus":null,"severity":"error","filePath":"connector/rabbitmq-connector/src/main/java/com/alibaba/otter/canal/connector/rabbitmq/producer/CanalRabbitMQProducer.java","lineNumber":62,"sourceCode":"    private static final Logger logger = LoggerFactory.getLogger(CanalRabbitMQProducer.class);\n\n    private Connection          connect;\n    private Channel             channel;\n\n    @Override\n    public void init(Properties properties) {\n        RabbitMQProducerConfig rabbitMQProperties = new RabbitMQProducerConfig();\n        this.mqProperties = rabbitMQProperties;\n        super.init(properties);\n        loadRabbitMQProperties(properties);\n\n        ConnectionFactory factory = new ConnectionFactory();\n        String servers = rabbitMQProperties.getHost();\n        if (servers.startsWith(\"amqp\")) {\n            try {\n                factory.setUri(servers);\n            } catch (URISyntaxException | NoSuchAlgorithmException | KeyManagementException ex) {\n                throw new CanalException(\"failed to parse host\", ex);\n            }\n        } else if (servers.contains(\":\")) {\n            String[] serverHostAndPort = AddressUtils.splitIPAndPort(servers);\n            factory.setHost(serverHostAndPort[0]);\n            factory.setPort(Integer.parseInt(serverHostAndPort[1]));\n        } else {\n            factory.setHost(servers);\n        }\n\n        if (mqProperties.getAliyunAccessKey().length() > 0 && mqProperties.getAliyunSecretKey().length() > 0\n            && mqProperties.getAliyunUid() > 0) {\n            factory.setCredentialsProvider(new AliyunCredentialsProvider(mqProperties.getAliyunAccessKey(),\n                mqProperties.getAliyunSecretKey(),\n                mqProperties.getAliyunUid()));\n        } else {\n            factory.setUsername(rabbitMQProperties.getUsername());\n            factory.setPassword(rabbitMQProperties.getPassword());\n        }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/alibaba/canal/blob/87be50e87686a3e8af08c368d0e1ffd1f59eb04a/connector/rabbitmq-connector/src/main/java/com/alibaba/otter/canal/connector/rabbitmq/producer/CanalRabbitMQProducer.java#L44-L80","documentation":"Thrown by CanalRabbitMQProducer.init when the host string starts with 'amqp' and ConnectionFactory.setUri(servers) raises URISyntaxException, NoSuchAlgorithmException, or KeyManagementException. The URI is malformed, uses an unsupported scheme, or specifies a TLS/algorithm the JVM does not provide.","triggerScenarios":"rabbitMQProperties.getHost() starts with 'amqp' and factory.setUri(servers) fails. Causes: missing/amqp-uri-syntax-violating characters (spaces, bad encoding); scheme not amqp/amqps; bad credentials embedded in the URI; amqps with a TLS algorithm unavailable in the JVM.","commonSituations":"Hand-typed amqp URI with a typo; URI containing special characters not percent-encoded; amqps URI on a JVM without the required TLS provider; missing/amqp-uri-syntax-violating credentials or vhost segment; copy-paste that included surrounding whitespace.","solutions":["Validate the URI format: scheme amqp/amqps, host, optional port, optional vhost, optional userinfo.","Percent-encode any special characters in the vhost or credentials (e.g. vhost '/test v' must encode the space).","Trim whitespace from the rabbitmq.host property before passing it.","If you do not need a full URI, use host[:port] form instead so the code takes the AddressUtils.splitIPAndPort branch."],"exampleFix":"// before\nString servers = rabbitMQProperties.getHost();\nif (servers.startsWith(\"amqp\")) {\n    factory.setUri(servers);\n}\n\n// after — validate and trim before setUri\nString servers = rabbitMQProperties.getHost().trim();\nif (servers.startsWith(\"amqp\")) {\n    try { factory.setUri(servers); }\n    catch (Exception ex) {\n        throw new CanalException(\"failed to parse host '\" + servers + \"': \" + ex.getMessage(), ex);\n    }\n}","handlingStrategy":"validation","validationCode":"String servers = rabbitMQProperties.getHost().trim();\nif (servers.startsWith(\"amqp\")) {\n    try { new java.net.URI(servers); }\n    catch (java.net.URISyntaxException e) {\n        throw new IllegalArgumentException(\"invalid amqp URI: \" + servers, e);\n    }\n}","typeGuard":"static boolean isAmqpUri(String s) {\n    if (s == null) return false;\n    String t = s.trim();\n    return t.startsWith(\"amqp://\") || t.startsWith(\"amqps://\");\n}","tryCatchPattern":null,"preventionTips":["Trim whitespace from rabbitmq.host before use.","Percent-encode special characters in vhost/credentials within amqp URIs.","Prefer host[:port] form unless you need userinfo/vhost in the URI."],"tags":["rabbitmq","configuration","uri","canal-connector","producer"],"backgroundTag":null,"analyzedSha":"87be50e87686a3e8af08c368d0e1ffd1f59eb04a","analyzedAt":"2026-08-14T04:30:11.918Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}