{"record":{"id":"add0c4188fd74157","repo":"yuliskov/SmartTube","slug":"type-type-is-not-compatible-with-address-sa","errorCode":null,"errorMessage":"type ${type} is not compatible with address ${sa}","messagePattern":"type (.+?) is not compatible with address (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/liskovsoft/smartyoutubetv2/common/proxy/Proxy.java","lineNumber":100,"sourceCode":"        sa = null;\n    }\n\n    /**\n     * Creates an entry representing a PROXY connection.\n     * Certain combinations are illegal. For instance, for types Http, and\n     * Socks, a SocketAddress <b>must</b> be provided.\n     * <P>\n     * Use the {@code Proxy.NO_PROXY} constant\n     * for representing a direct connection.\n     *\n     * @param type the {@code Type} of the proxy\n     * @param sa the {@code SocketAddress} for that proxy\n     * @throws IllegalArgumentException when the type and the address are\n     * incompatible\n     */\n    public Proxy(Type type, SocketAddress sa) {\n        if ((type == Type.DIRECT) || !(sa instanceof PasswdInetSocketAddress))\n            throw new IllegalArgumentException(\"type \" + type + \" is not compatible with address \" + sa);\n        this.type = type;\n        this.sa = sa;\n    }\n\n    /**\n     * Returns the proxy type.\n     *\n     * @return a Type representing the proxy type\n     */\n    public Type type() {\n        return type;\n    }\n\n    /**\n     * Returns the socket address of the proxy, or\n     * {@code null} if its a direct connection.\n     *\n     * @return a {@code SocketAddress} representing the socket end","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/yuliskov/SmartTube/blob/3de8d90593e0166f012ca18cc3c7ba45bfd68ac4/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/proxy/Proxy.java#L82-L118","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Build the address first via PasswdInetSocketAddress.createUnresolved(host, port, user, pass) and pass that to the Proxy","Use Proxy.NO_PROXY for direct connections instead of Type.DIRECT","Never feed raw InetSocketAddress or other SocketAddress subclasses into this constructor"],"exampleFix":"// before\nProxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port)); // throws\n\n// after\nPasswdInetSocketAddress addr =\n        PasswdInetSocketAddress.createUnresolved(host, port, user, pass);\nProxy proxy = new Proxy(Proxy.Type.HTTP, addr);","handlingStrategy":"validation","validationCode":"if (type == Proxy.Type.DIRECT || !(sa instanceof PasswdInetSocketAddress)) {\n    // use Proxy.NO_PROXY for direct, or wrap host/port/credentials first\n}\nProxy proxy = new Proxy(type, sa);","typeGuard":"static boolean isCompatible(@Nullable Proxy.Type type, @Nullable SocketAddress sa) {\n    return type != null && type != Proxy.Type.DIRECT && sa instanceof PasswdInetSocketAddress;\n}","tryCatchPattern":null,"preventionTips":["Always build addresses through PasswdInetSocketAddress.createUnresolved","Represent direct connections with Proxy.NO_PROXY, never Type.DIRECT","Keep java.net.Proxy objects and this custom Proxy strictly separated"],"tags":["proxy","socket-address","type-mismatch","api-misuse"],"backgroundTag":"proxy-type-address-mismatch","analyzedSha":"3de8d90593e0166f012ca18cc3c7ba45bfd68ac4","analyzedAt":"2026-08-22T09:19:26.383Z","schemaVersion":2},"datasetVersion":"2026-08-22T14:17:55.899Z"}