alibaba/canal · error · RuntimeException
address[{}] is illegal, eg.127.0.0.1:3306
Error message
address[{}] is illegal, eg.127.0.0.1:3306 What it means
Thrown by SocketAddressEditor.setAsText when Spring is binding a string property to an InetSocketAddress but the text does not split into exactly an IP and a port. AddressUtils.splitIPAndPort uses lastIndexOf(':') to split; if there is no colon the array is empty (sets null), but if there are extra colons or multiple parts it yields length != 2 and this RuntimeException fires. The expected form is ip:port, e.g. 127.0.0.1:3306.
Source
Thrown at instance/spring/src/main/java/com/alibaba/otter/canal/instance/spring/support/SocketAddressEditor.java:21
import java.beans.PropertyEditorSupport;
import java.net.InetSocketAddress;
import org.springframework.beans.PropertyEditorRegistrar;
import org.springframework.beans.PropertyEditorRegistry;
import com.alibaba.otter.canal.common.utils.AddressUtils;
public class SocketAddressEditor extends PropertyEditorSupport implements PropertyEditorRegistrar {
public void registerCustomEditors(PropertyEditorRegistry registry) {
registry.registerCustomEditor(InetSocketAddress.class, this);
}
public void setAsText(String text) throws IllegalArgumentException {
String[] addresses = AddressUtils.splitIPAndPort(text);
if (addresses.length > 0) {
if (addresses.length != 2) {
throw new RuntimeException("address[" + text + "] is illegal, eg.127.0.0.1:3306");
} else {
setValue(new InetSocketAddress(addresses[0], Integer.valueOf(addresses[1])));
}
} else {
setValue(null);
}
}
}
View on GitHub (pinned to 87be50e876)
Solutions
- Set the address property in ip:port form, e.g. canal.instance.master.address = 127.0.0.1:3306.
- For IPv6 use bracketed form [::1]:3306 (splitIPAndPort strips brackets).
- Ensure exactly one colon separates host and port; quote the value if your shell/config strips colons.
- Verify the port component is numeric to avoid a follow-on NumberFormatException.
Example fix
// before canal.instance.master.address = 127.0.0.1 // after canal.instance.master.address = 127.0.0.1:3306
Defensive patterns
Strategy: validation
Validate before calling
static InetSocketAddress parse(String hostPort) {
int colon = hostPort.replace("[","").replace("]","").lastIndexOf(':');
if (colon <= 0) throw new IllegalArgumentException("address must be host:port, got: " + hostPort);
String host = hostPort.substring(0, colon), portStr = hostPort.substring(colon + 1);
int port = Integer.parseInt(portStr); // throws if non-numeric -> fail fast
return new InetSocketAddress(host.replace("[","").replace("]",""), port);
} Type guard
boolean isHostPort(String s) {
int c = s == null ? -1 : s.replace("[","").replace("]","").lastIndexOf(':');
if (c <= 0) return false;
try { int p = Integer.parseInt(s.substring(c + 1)); return p > 0 && p < 65536; }
catch (NumberFormatException e) { return false; }
} Prevention
- Always specify addresses as ip:port in instance.properties.
- Validate address strings in config-loading tests.
- Use bracketed form for IPv6 ([::1]:3306).
When it happens
Trigger: Spring injects a value into an InetSocketAddress-typed property (canal.instance.master.address, canal.instance.standby.address, data source addresses). The provided string fails the 2-part split, e.g. 'localhost' (no port), '127.0.0.1' (no port), ':3306' (empty host), or a value with a stray colon.
Common situations: Typo in instance.properties master.address (missing port), copy-paste leaving a trailing colon, or passing a hostname with a port already baked in incorrectly. Note Integer.valueOf(addresses[1]) can also throw NumberFormatException for a non-numeric port, producing a different exception.
Related errors
- Unsupported ssl mode: {}
- Server certificate identity check failed. The certificate Co
- load manager config failed.
- Unknown host
- canal.adminUser is empty , pls check https://github.com/alib
AI-assisted analysis of alibaba/canal@87be50e876 (2026-08-14).
Data as JSON: /api/errors/df57450ad6a2955a.
Report an issue: GitHub.