{"record":{"id":"bcab13f1c133d3b6","repo":"aeron-io/aeron","slug":"invalid-address-length-address-length","errorCode":null,"errorMessage":"Invalid address length: ${address.length}","messagePattern":"Invalid address length: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"aeron-client/src/main/java/io/aeron/protocol/ResolutionEntryFlyweight.java","lineNumber":246,"sourceCode":"    public int ageInMs()\n    {\n        return getInt(AGE_IN_MS_FIELD_OFFSET, LITTLE_ENDIAN);\n    }\n\n    /**\n     * Put the address into the resolution entry. It must come after calling {@link #resType(byte)}.\n     *\n     * @param address to be written for the resolution entry.\n     * @return this for a fluent API.\n     */\n    public ResolutionEntryFlyweight putAddress(final byte[] address)\n    {\n        switch (resType())\n        {\n            case RES_TYPE_NAME_TO_IP4_MD:\n                if (ADDRESS_LENGTH_IP4 != address.length)\n                {\n                    throw new IllegalArgumentException(\"Invalid address length: \" + address.length);\n                }\n                putBytes(ADDRESS_FIELD_OFFSET, address, 0, ADDRESS_LENGTH_IP4);\n                break;\n\n            case RES_TYPE_NAME_TO_IP6_MD:\n                if (ADDRESS_LENGTH_IP6 != address.length)\n                {\n                    throw new IllegalArgumentException(\"Invalid address length: \" + address.length);\n                }\n                putBytes(ADDRESS_FIELD_OFFSET, address, 0, ADDRESS_LENGTH_IP6);\n                break;\n\n            default:\n                throw new IllegalStateException(\"unknown RES_TYPE=\" + resType());\n        }\n\n        return this;\n    }","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/aeron-io/aeron/blob/6d60124e15e35c11b49ba2e3c2c2858a09a18803/aeron-client/src/main/java/io/aeron/protocol/ResolutionEntryFlyweight.java#L228-L264","documentation":"ResolutionEntryFlyweight.putAddress validates the address byte-array length against the resolution type before writing it into the flyweight. For RES_TYPE_NAME_TO_IP4_MD the address must be exactly ADDRESS_LENGTH_IP4 (4) bytes; any other length throws IllegalArgumentException. This guards against writing malformed addresses into name-to-IP4 resolution entries in the control protocol.","triggerScenarios":"Calling putAddress with an address array whose length is not 4 while resType() is RES_TYPE_NAME_TO_IP4_MD — e.g. passing an IPv6 address, a hostname byte array, or an empty array.","commonSituations":"Mixing IPv4 and IPv6 addresses when building resolution entries; parsing a name-resolution response and re-encoding with the wrong resType; test fixtures with placeholder addresses.","solutions":["Check address.length == 4 before calling putAddress for IP4 entries.","Ensure resType() matches the actual address family of the data.","For IPv6 data, set the entry type to RES_TYPE_NAME_TO_IP6_MD instead.","Validate the source of the address bytes (e.g. InetAddress.getAddress() length) before encoding."],"exampleFix":"// before\nflyweight.resType(RES_TYPE_NAME_TO_IP4_MD);\nflyweight.putAddress(inet6Address.getAddress()); // 16 bytes into IP4 entry\n// after\nfinal byte[] bytes = address.getAddress();\nflyweight.resType(bytes.length == 4 ? RES_TYPE_NAME_TO_IP4_MD : RES_TYPE_NAME_TO_IP6_MD);\nflyweight.putAddress(bytes);","handlingStrategy":"validation","validationCode":"if (address != null && address.length == ResolutionEntryFlyweight.ADDRESS_LENGTH_IP4\n    && flyweight.resType() == ResolutionEntryFlyweight.RES_TYPE_NAME_TO_IP4_MD)\n{\n    flyweight.putAddress(address);\n}","typeGuard":"boolean isIp4AddressBytes(final byte[] address)\n{\n    return address != null && address.length == 4;\n}","tryCatchPattern":"try\n{\n    flyweight.putAddress(address);\n}\ncatch (final IllegalArgumentException ex)\n{\n    LOGGER.error(\"resolution entry address length mismatch\", ex);\n}","preventionTips":["Match resType to the address family before putAddress.","Use InetAddress.getAddress() so lengths are canonical (4 or 16).","Never pass hostname strings' bytes as the address payload.","Add unit tests covering both address families."],"tags":["protocol","ipv4","argument-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"6d60124e15e35c11b49ba2e3c2c2858a09a18803","analyzedAt":"2026-09-12T11:17:07.683Z","contentChangedAt":"2026-09-12T11:17:07.683Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}