apache/dubbo · error · IllegalArgumentException

Illegal Argument pattern or hostName. Pattern:${pattern}, Ho

Error message

Illegal Argument pattern or hostName. Pattern:${pattern}, Host:${host}

What it means

NetUtils.matchIpRange requires both the pattern and the host to be non-null. If either is null it throws IllegalArgumentException because IP-range matching is undefined without both operands.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java:776

        // if the pattern is subnet format, it will not be allowed to config port param in pattern.
        if (pattern.contains("/")) {
            CIDRUtils utils = new CIDRUtils(pattern);
            return utils.isInRange(host);
        }

        return matchIpRange(pattern, host, port);
    }

    /**
     * @param pattern
     * @param host
     * @param port
     * @return
     * @throws UnknownHostException
     */
    public static boolean matchIpRange(String pattern, String host, int port) throws UnknownHostException {
        if (pattern == null || host == null) {
            throw new IllegalArgumentException(
                    "Illegal Argument pattern or hostName. Pattern:" + pattern + ", Host:" + host);
        }
        pattern = pattern.trim();
        if ("*.*.*.*".equals(pattern) || "*".equals(pattern)) {
            return true;
        }

        InetAddress inetAddress = InetAddress.getByName(host);
        boolean isIpv4 = isValidV4Address(inetAddress);
        String[] hostAndPort = getPatternHostAndPort(pattern, isIpv4);
        if (hostAndPort[1] != null && !hostAndPort[1].equals(String.valueOf(port))) {
            return false;
        }
        pattern = hostAndPort[0];

        String splitCharacter = SPLIT_IPV4_CHARACTER;
        if (!isIpv4) {
            splitCharacter = SPLIT_IPV6_CHARACTER;

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Validate that both pattern and host are non-null before calling matchIpRange
  2. Provide explicit defaults for optional pattern config and skip matching when unset
  3. Log the unresolved host early so the null source is traceable

Example fix

// before
if (NetUtils.matchIpRange(configPattern, remoteHost, port)) { ... }
// after
if (configPattern != null && remoteHost != null
        && NetUtils.matchIpRange(configPattern, remoteHost, port)) { ... }
Defensive patterns

Strategy: validation

Validate before calling

if (pattern == null || host == null) { /* skip or default; do not call matchIpRange */ }
else { boolean ok = NetUtils.matchIpRange(pattern, host, port); }

Type guard

static boolean canMatchIp(String pattern, String host) { return pattern != null && host != null; }

Try / catch

try { NetUtils.matchIpRange(pattern, host, port); }
catch (IllegalArgumentException e) { /* pattern or host was null */ }

Prevention

When it happens

Trigger: Calling NetUtils.matchIpRange(pattern, host, port) (or the IP-expression matcher) where pattern or host resolved to null — e.g. from a missing config value or an unresolvable remote address.

Common situations: Firewall/ACL rules referencing an unset 'dubbo.ip-pattern' property; a remote socket whose host string could not be resolved; null propagation from a previous lookup step.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/576c597de78ed4f6. Report an issue: GitHub.