apache/seatunnel · error · IllegalArgumentException

SNMP source port must be between 1 and 65535

Error message

SNMP source port must be between 1 and 65535

What it means

SnmpSourceConfig.validate() rejects a port outside the valid TCP/UDP port range 1-65535. The port identifies the SNMP agent's UDP endpoint; a value of 0 or negative is meaningless, and anything above 65535 cannot be represented as a port number.

Solutions

  1. Set port to the SNMP agent's actual port, typically 161 (default) or 10161 for some devices
  2. Ensure the value is an integer between 1 and 65535

Example fix

// before
port = 0
// after
port = 161
Defensive patterns

Strategy: validation

Validate before calling

Integer port = config.get(SnmpSourceOptions.PORT);
if (port == null || port < 1 || port > 65535) {
    throw new IllegalArgumentException("port must be an integer in [1, 65535]");
}

Type guard

boolean isValidPort(Integer port) {
    return port != null && port >= 1 && port <= 65535;
}

Try / catch

try {
    SnmpSourceConfig cfg = new SnmpSourceConfig(config);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("port must be between 1 and 65535")) {
        // log the offending port value and correct config path
    }
    throw e;
}

Prevention

When it happens

Trigger: SnmpSourceConfig constructor calls validate() after reading SnmpSourceOptions.PORT; the error fires when the configured port option is < 1 or > 65535 (e.g. port = 0, port = -1, port = 70000).

Common situations: Port 0 used to mean 'auto' by habit from other tools; pasting an HTTPS port like 8443 into the wrong field; copying a value with extra characters (e.g. '161 ') or mixing up a device serial number for the port.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/456b09f664cb0959. Report an issue: GitHub.

Appendix: source

Thrown at seatunnel-connectors-v2/connector-snmp/src/main/java/org/apache/seatunnel/connectors/seatunnel/snmp/config/SnmpSourceConfig.java:65

    /** Creates an SNMP source configuration from connector options. */
    public SnmpSourceConfig(ReadonlyConfig config) {
        String configuredHost = config.get(SnmpSourceOptions.HOST);
        if (isBlank(configuredHost)) {
            throw new IllegalArgumentException("SNMP source host must not be blank");
        }
        this.host = configuredHost.trim();
        this.port = config.get(SnmpSourceOptions.PORT);
        this.community = config.get(SnmpSourceOptions.COMMUNITY);
        this.oids = parseOids(config.get(SnmpSourceOptions.OIDS));
        this.timeoutMillis = config.get(SnmpSourceOptions.TIMEOUT_MILLIS);
        this.retries = config.get(SnmpSourceOptions.RETRIES);
        this.pollIntervalMillis = config.get(SnmpSourceOptions.POLL_INTERVAL_MILLIS);
        validate();
    }

    private void validate() {
        if (port < 1 || port > 65535) {
            throw new IllegalArgumentException("SNMP source port must be between 1 and 65535");
        }
        if (isBlank(community)) {
            throw new IllegalArgumentException("SNMP source community must not be blank");
        }
        if (timeoutMillis <= 0) {
            throw new IllegalArgumentException("SNMP source timeout_millis must be greater than 0");
        }
        if (retries < 0) {
            throw new IllegalArgumentException("SNMP source retries must not be negative");
        }
        if (pollIntervalMillis <= 0) {
            throw new IllegalArgumentException(
                    "SNMP source poll_interval_millis must be greater than 0");
        }
    }

    private static boolean isBlank(String value) {
        return value == null || value.trim().isEmpty();

View on GitHub (pinned to cf67b549a7)