aeron-io/aeron · error · IllegalArgumentException

invalid port

Error message

invalid port: <s>

What it means

Thrown during InterfaceSearchAddress.getPort when the string ends with a colon with no port digits after it (e.g. '10.0.0.1:'). A colon indicates a port follows, so an empty port is invalid. It surfaces via the port accessor.

Solutions

  1. Supply a concrete port after the colon (e.g. '0.0.0.0:40456') or remove the colon to use the default port of 0
  2. Check upstream code that builds the address string to ensure the port variable is non-empty
  3. Validate the address format with a regex or parse attempt before configuring the driver

Example fix

// before
String addr = host + ":" + port; // port == ""
// after
String addr = (port == null || port.isEmpty()) ? host : host + ":" + port;
Defensive patterns

Strategy: validation

Validate before calling

// reject dangling port colon before use
static boolean validPortSpec(String s) {
    int i = s.indexOf(':');
    if (i < 0) return true;
    int end = s.indexOf('/', i);
    String port = s.substring(i + 1, end < 0 ? s.length() : end);
    return !port.isEmpty() && port.chars().allMatch(Character::isDigit);
}

Type guard

null

Try / catch

try {
    addr.port();
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("invalid port: ")) {
        // treat as port 0 (ephemeral) by fixing the spec string
    } else { throw e; }
}

Prevention

When it happens

Trigger: Configuring an interface search address ending in ':' such as 'localhost:' or '0.0.0.0:'.

Common situations: Truncated configuration strings, placeholder ports never replaced, or concatenating host+':'+port where the port variable was empty.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of aeron-io/aeron@6d60124e15 (2026-09-12). Data as JSON: /api/errors/0b42aebf7fd13c40. Report an issue: GitHub.

Appendix: source

Thrown at aeron-driver/src/main/java/io/aeron/driver/media/InterfaceSearchAddress.java:190

        {
            throw new IllegalArgumentException("invalid subnet: " + s);
        }

        final int subnetStringBegin = slashIndex + 1;

        return AsciiEncoding.parseIntAscii(s, subnetStringBegin, s.length() - subnetStringBegin);
    }

    private static int getPort(
        final String s, final int slashIndex, final int colonIndex, final int rightAngleBraceIndex)
    {
        if (colonIndex < 0 || rightAngleBraceIndex > colonIndex)
        {
            return 0;
        }
        else if (s.length() - 1 == colonIndex)
        {
            throw new IllegalArgumentException("invalid port: " + s);
        }

        final int portStringBegin = colonIndex + 1;
        final int portStringEnd = slashIndex > 0 ? slashIndex : s.length();

        return AsciiEncoding.parseIntAscii(s, portStringBegin, portStringEnd - portStringBegin);
    }

    private static String getAddress(
        final String s, final int slashIndex, final int colonIndex, final int rightAngleBraceIndex)
    {
        int addressEnd = s.length();

        if (slashIndex >= 0)
        {
            addressEnd = slashIndex;
        }

View on GitHub (pinned to 6d60124e15)