aeron-io/aeron · error · IllegalArgumentException

Insufficient length:

Error message

Insufficient length: 

What it means

getAddress for RES_TYPE_NAME_TO_IP4_MD throws IllegalArgumentException when the caller-supplied dstBuffer is shorter than the 4-byte IPv4 address it must hold. This is a defensive pre-copy length check to prevent ArrayIndexOutOfBoundsException inside the underlying getBytes copy.

Solutions

  1. Allocate dstBuffer with at least ADDRESS_LENGTH_IP4 (4) bytes for IPv4 entries — using the IP6 length (16) for all cases is safe
  2. Use the static addressLength(resType) helper to size the buffer per entry
  3. Switch to the appendTo(Appendable) variant if you only need the address as text

Example fix

// before
byte[] dst = new byte[0];
int len = entry.getAddress(dst);
// after
byte[] dst = new byte[ResolutionEntryFlyweight.ADDRESS_LENGTH_IP6];
int len = entry.getAddress(dst);
Defensive patterns

Strategy: validation

Validate before calling

if (dstBuffer.length < ResolutionEntryFlyweight.ADDRESS_LENGTH_IP4) { throw new IllegalArgumentException("dst too small"); }

Type guard

null

Try / catch

try { int len = entry.getAddress(dst); }
catch (IllegalArgumentException e) { /* resize buffer and retry */ }

Prevention

When it happens

Trigger: Calling getAddress(byte[] dstBuffer) on an entry with resType RES_TYPE_NAME_TO_IP4_MD while dstBuffer.length < ADDRESS_LENGTH_IP4 (4).

Common situations: Reusing a shared scratch byte[] sized for one address family (e.g. 16 bytes for IPv6 names) with entries of the other family, or passing a freshly allocated zero-length array.

Related errors


AI-assisted analysis of aeron-io/aeron@6d60124e15 (2026-09-12). Data as JSON: /api/errors/90d8d37001837364. Report an issue: GitHub.

Appendix: source

Thrown at aeron-client/src/main/java/io/aeron/protocol/ResolutionEntryFlyweight.java:279

        }

        return this;
    }

    /**
     * Get the address for the entry by copying it into the destination buffer.
     *
     * @param dstBuffer into which the address will be copied.
     * @return length of the address copied.
     */
    public int getAddress(final byte[] dstBuffer)
    {
        switch (resType())
        {
            case RES_TYPE_NAME_TO_IP4_MD:
                if (ADDRESS_LENGTH_IP4 > dstBuffer.length)
                {
                    throw new IllegalArgumentException("Insufficient length: " + dstBuffer.length);
                }
                getBytes(ADDRESS_FIELD_OFFSET, dstBuffer, 0, ADDRESS_LENGTH_IP4);
                return ADDRESS_LENGTH_IP4;

            case RES_TYPE_NAME_TO_IP6_MD:
                if (ADDRESS_LENGTH_IP6 > dstBuffer.length)
                {
                    throw new IllegalArgumentException("Insufficient length: " + dstBuffer.length);
                }
                getBytes(ADDRESS_FIELD_OFFSET, dstBuffer, 0, ADDRESS_LENGTH_IP6);
                return ADDRESS_LENGTH_IP6;
        }

        throw new IllegalStateException("unknown RES_TYPE=" + resType());
    }

    /**
     * Append the address to the provided {@link Appendable} in ASCII format.

View on GitHub (pinned to 6d60124e15)