apache/dolphinscheduler · error · IllegalArgumentException

host:port '%s' illegal.

Error message

host:port '%s' illegal.

What it means

Guard in BaseDataSourceParamDTO.setHostAndPortByAddress: after parsing the jdbc address, it throws when no host could be extracted or no ':port' segment was found — i.e. the host:port part of the address (quoted in the message) lacks a port or is empty/malformed, like 'jdbc:mysql://host' without ':3306'.

Source

Thrown at dolphinscheduler-datasource-plugin/dolphinscheduler-datasource-api/src/main/java/org/apache/dolphinscheduler/plugin/datasource/api/datasource/BaseDataSourceParamDTO.java:79

        }
        address = address.trim();

        int doubleSlashIndex = address.indexOf(Constants.DOUBLE_SLASH);
        // trim address like 'jdbc:mysql://host:port/xxx' ends with '/xxx'
        int slashIndex = address.indexOf(Constants.SLASH, doubleSlashIndex + 2);
        String hostPortString = slashIndex == -1 ? address.substring(doubleSlashIndex + 2)
                : address.substring(doubleSlashIndex + 2, slashIndex);

        ArrayList<String> hosts = new ArrayList<>();
        String portString = null;
        for (String hostPort : hostPortString.split(Constants.COMMA)) {
            String[] parts = hostPort.split(Constants.COLON);
            hosts.add(parts[0]);
            if (portString == null && parts.length > 1)
                portString = parts[1];
        }
        if (hosts.size() == 0 || portString == null) {
            throw new IllegalArgumentException(String.format("host:port '%s' illegal.", hostPortString));
        }

        this.host = String.join(Constants.COMMA, hosts);
        this.port = Integer.parseInt(portString);
    }

    /**
     * Get the datasource type
     * see{@link DbType}
     *
     * @return datasource type code
     */
    public abstract DbType getType();
}

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Include an explicit port in the address (jdbc:mysql://host:3306)
  2. Check the address format matches what the parser expects (//host1:port,host2:port)
  3. Set host and port fields directly instead of relying on address parsing

Example fix

// before
param.setAddress("jdbc:mysql://localhost");
// after
param.setAddress("jdbc:mysql://localhost:3306");
Defensive patterns

Strategy: validation

Validate before calling

boolean addrOk = address != null && address.matches("^jdbc:[a-z0-9]+://[\w.,:]+(:\d+)(/.*)?$");

Try / catch

try { dto.setHostAndPortByAddress(address); } catch (IllegalArgumentException e) { /* prompt user for host:port */ }

Prevention

When it happens

Trigger: Address strings lacking a port (e.g. 'jdbc:mysql://localhost') or lacking hosts (e.g. 'jdbc:mysql://:3306'), or malformed comma-separated host lists.

Common situations: Omitting the port for the default, copy-pasting a URL without the port, ZooKeeper-style address variations that the parser cannot handle.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/aaba3b541712fd24. Report an issue: GitHub.