apache/cassandra · error · IllegalStateException

Checksum is larger than 32 bytes!

Error message

Checksum is larger than 32 bytes!

What it means

getValue32 is a helper on Checksumed wrappers (e.g. CRC32-based checksums embedded in I/O streams) that returns the checksum truncated to an int. If the checksum value exceeds 32 bits (any bit set in the upper 32 bits) it cannot fit, so an IllegalStateException is thrown instead of silently truncating.

Source

Thrown at src/java/org/apache/cassandra/io/util/Checksumed.java:39

import java.util.zip.Checksum;

public interface Checksumed
{
    Checksum checksum();

    default long getAndResetChecksum()
    {
        Checksum c = checksum();
        long v = c.getValue();
        c.reset();
        return v;
    }

    default int getValue32()
    {
        long v = checksum().getValue();
        if (Long.numberOfLeadingZeros(v) < 32)
            throw new IllegalStateException("Checksum is larger than 32 bytes!");
        return (int) v;
    }

    default int getValue32AndResetChecksum()
    {
        Checksum c = checksum();
        long v = c.getValue();
        if (Long.numberOfLeadingZeros(v) < 32)
            throw new IllegalStateException("Checksum is larger than 32 bytes!");
        c.reset();
        return (int) v;
    }

    default void resetChecksum()
    {
        checksum().reset();
    }
}

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Use a 32-bit checksum (java.util.zip.CRC32 / Adler32) wherever getValue32 is consumed
  2. Mask to 32 bits explicitly if truncation is intended: (int) checksum().getValue()
  3. Or use the full long via checksum().getValue() instead of getValue32

Example fix

// before
int v = checksumed.getValue32(); // throws for 64-bit checksum
// after
long v = checksumed.checksum().getValue(); int v32 = (int) v; // explicit truncate
Defensive patterns

Strategy: type-guard

Validate before calling

long v = checksum().getValue(); if (Long.numberOfLeadingZeros(v) < 32) switchToLongChecksumPath(v);

Type guard

static boolean fitsInt(Checksum c) { return Long.numberOfLeadingZeros(c.getValue()) >= 32; }

Try / catch

try { int v = checksumed.getValue32(); } catch (IllegalStateException e) { long v = checksumed.checksum().getValue(); /* handle 64-bit */ }

Prevention

When it happens

Trigger: Calling getValue32() on a Checksum implementation whose current accumulated value exceeds Integer range — only possible with a non-standard checksum algorithm (CRC32 variants normally fit in 32 bits); indicates the wrong Checksum instance was plugged in.

Common situations: Custom Checksum implementations (e.g. CRC64, xxHash-64) wired into a stream that expects a 32-bit CRC, misuse of the Checksumed API in custom tooling.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/b7ff57f46951a23a. Report an issue: GitHub.