gradle/gradle · error · IllegalArgumentException

Invalid hash code length: %d bytes

Error message

Invalid hash code length: %d bytes

What it means

Error "Invalid hash code length: %d bytes" thrown in gradle/gradle.

Source

Thrown at platforms/core-execution/hashing/src/main/java/org/gradle/internal/hash/HashCode.java:75

    static HashCode fromBytes(byte[] bytes, Usage usage) {
        switch (bytes.length) {
            case 16:
                return new HashCode128(
                    bytesToLong(bytes, 0),
                    bytesToLong(bytes, 8)
                );
            default:
                return new ByteArrayBackedHashCode(usage == CLONE_BYTES_IF_NECESSARY
                    ? bytes.clone()
                    : bytes);
        }
    }

    public static HashCode fromBytes(byte[] bytes) {
        // Make sure hash codes are serializable with a single byte length
        if (bytes.length < MIN_NUMBER_OF_BYTES || bytes.length > MAX_NUMBER_OF_BYTES) {
            throw new IllegalArgumentException(String.format("Invalid hash code length: %d bytes", bytes.length));
        }
        return fromBytes(bytes, CLONE_BYTES_IF_NECESSARY);
    }

    /**
     * Decodes the hash code from a string.
     * <p>
     * A corresponding operation for encoding/decoding is {@link #toString()}:
     * <pre>{@code
     *      assertEquals(hash, HashCode.fromString(hash.toString()))
     * }</pre>
     * <p>
     * This method does not work with {@link #toCompactString()}.
     */
    public static HashCode fromString(String string) {
        int length = string.length();

        if (length % 2 != 0

View on GitHub (pinned to 534f27719b)

Solutions

  1. The hash byte array has an invalid length. Supply a hash with the correct byte length for the algorithm (e.g. 16 for MD5, 20 for SHA-1).

When it happens

Trigger: Thrown at platforms/core-execution/hashing/src/main/java/org/gradle/internal/hash/HashCode.java:75 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22). Data as JSON: /api/errors/93b919b88280e5e2. Report an issue: GitHub.