yuliskov/SmartTube · error · IllegalArgumentException

type ${type} is not compatible with address ${sa}

Error message

type ${type} is not compatible with address ${sa}

What it means

This Proxy is a local reimplementation of java.net.Proxy restricted to authenticated proxies: the constructor requires type != DIRECT and sa instanceof PasswdInetSocketAddress, echoing the JDK wording 'type ... is not compatible with address'. Because a null address also fails the instanceof check, constructing with no SocketAddress throws the same way.

Source

Thrown at common/src/main/java/com/liskovsoft/smartyoutubetv2/common/proxy/Proxy.java:100

        sa = null;
    }

    /**
     * Creates an entry representing a PROXY connection.
     * Certain combinations are illegal. For instance, for types Http, and
     * Socks, a SocketAddress <b>must</b> be provided.
     * <P>
     * Use the {@code Proxy.NO_PROXY} constant
     * for representing a direct connection.
     *
     * @param type the {@code Type} of the proxy
     * @param sa the {@code SocketAddress} for that proxy
     * @throws IllegalArgumentException when the type and the address are
     * incompatible
     */
    public Proxy(Type type, SocketAddress sa) {
        if ((type == Type.DIRECT) || !(sa instanceof PasswdInetSocketAddress))
            throw new IllegalArgumentException("type " + type + " is not compatible with address " + sa);
        this.type = type;
        this.sa = sa;
    }

    /**
     * Returns the proxy type.
     *
     * @return a Type representing the proxy type
     */
    public Type type() {
        return type;
    }

    /**
     * Returns the socket address of the proxy, or
     * {@code null} if its a direct connection.
     *
     * @return a {@code SocketAddress} representing the socket end

View on GitHub (pinned to 3de8d90593)

Solutions

  1. Build the address first via PasswdInetSocketAddress.createUnresolved(host, port, user, pass) and pass that to the Proxy
  2. Use Proxy.NO_PROXY for direct connections instead of Type.DIRECT
  3. Never feed raw InetSocketAddress or other SocketAddress subclasses into this constructor

Example fix

// before
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); // throws

// after
PasswdInetSocketAddress addr =
        PasswdInetSocketAddress.createUnresolved(host, port, user, pass);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
Defensive patterns

Strategy: validation

Validate before calling

if (type == Proxy.Type.DIRECT || !(sa instanceof PasswdInetSocketAddress)) {
    // use Proxy.NO_PROXY for direct, or wrap host/port/credentials first
}
Proxy proxy = new Proxy(type, sa);

Type guard

static boolean isCompatible(@Nullable Proxy.Type type, @Nullable SocketAddress sa) {
    return type != null && type != Proxy.Type.DIRECT && sa instanceof PasswdInetSocketAddress;
}

Prevention

When it happens

Trigger: Passing a plain java.net.InetSocketAddress (no credentials) to this Proxy; constructing Proxy(Type.DIRECT, address), where direct connections are meant to be represented by Proxy.NO_PROXY; passing null sa.

Common situations: Mixing system java.net proxy objects with this custom class; porting java.net.Proxy code that tolerated DIRECT-with-address patterns; forgetting to wrap host/port/credentials into PasswdInetSocketAddress before building the Proxy.

Related errors


AI-assisted analysis of yuliskov/SmartTube@3de8d90593 (2026-08-22). Data as JSON: /api/errors/add0c4188fd74157. Report an issue: GitHub.