{"record":{"id":"3a4ed9a8bdb73fbe","repo":"alibaba/arthas","slug":"zero-length-message","errorCode":null,"errorMessage":"zero length message","messagePattern":"zero length message","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"client/src/main/java/org/apache/commons/net/telnet/TelnetClient.java","lineNumber":223,"sourceCode":"     * the first byte in {@code message} should be the appropriate telnet\n     * option code.\n     *\n     * <p>\n     * This method does not wait for any response. Subnegotiation messages\n     * sent by the remote end can be handled by registering an approrpriate\n     * {@link TelnetOptionHandler}.\n     * </p>\n     *\n     * @param message option code followed by subnegotiation payload\n     * @throws IllegalArgumentException if {@code message} has length zero\n     * @throws IOException if an I/O error occurs while writing the message\n     * @since 3.0\n     ***/\n    public void sendSubnegotiation(int[] message)\n    throws IOException, IllegalArgumentException\n    {\n        if (message.length < 1) {\n            throw new IllegalArgumentException(\"zero length message\");\n        }\n        _sendSubnegotiation(message);\n    }\n\n    /***\n     * Sends a command byte to the remote peer, adding the IAC prefix.\n     *\n     * <p>\n     * This method does not wait for any response. Messages\n     * sent by the remote end can be handled by registering an approrpriate\n     * {@link TelnetOptionHandler}.\n     * </p>\n     *\n     * @param command the code for the command\n     * @throws IOException if an I/O error occurs while writing the message\n     * @throws IllegalArgumentException  on error\n     * @since 3.0\n     ***/","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/client/src/main/java/org/apache/commons/net/telnet/TelnetClient.java#L205-L241","documentation":"TelnetClient.sendSubnegotiation(int[] message) requires at least one byte (the option code) before writing the subnegotiation payload. An empty int[] is rejected with IllegalArgumentException(\"zero length message\") before any I/O. This is the commons-net Telnet option-subnegotiation API used internally by the Arthas telnet client.","triggerScenarios":"Calling sendSubnegotiation(new int[0]) or with a list that resolved to zero elements — typically a programmatic caller building an option payload that ended up empty due to a filtering/mapping step returning nothing.","commonSituations":"Custom TelnetOptionHandler producing an empty subnegotiation array; a code path that sends subnegotiation unconditionally even when there is no payload; defensive/guard code removed by mistake.","solutions":["Guard the call: only invoke sendSubnegotiation when message.length >= 1.","Fix the upstream logic that builds the payload so it always includes the leading option code.","If using an option handler, ensure its subnegotiation callbacks return non-empty arrays (or null/no-op)."],"exampleFix":"// before\nclient.sendSubnegotiation(payload);  // payload may be int[0]\n\n// after\nif (payload != null && payload.length > 0) {\n    client.sendSubnegotiation(payload);\n}","handlingStrategy":"validation","validationCode":"if (message != null && message.length > 0) {\n    client.sendSubnegotiation(message);\n}","typeGuard":"static boolean hasSubnegotiationPayload(int[] m) {\n    return m != null && m.length > 0;\n}","tryCatchPattern":"try {\n    client.sendSubnegotiation(payload);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"zero length message\")) {\n        // nothing to send; no-op\n    } else throw e;\n}","preventionTips":["Guard sendSubnegotiation with a length check.","Ensure option handlers return non-empty arrays when they send data.","Unit-test handlers that may produce empty payloads."],"tags":["client","telnet","validation","commons-net"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}