nathanmarz/storm · error · IllegalArgumentException

Field must be a power of 2.

Error message

Field ${name} must be a power of 2.

What it means

The powerOf2Validator checks that the configured integer is positive and a power of two (i>0 && (i&(i-1))==0). Otherwise validateField throws this IllegalArgumentException. Storm requires such values (e.g. buffer/worker sizes) so it can use efficient bit-based sizing.

Solutions

  1. Change the value to the nearest power of 2 (e.g. 1024, 4096, 65536).
  2. Check which key failed and its documented constraints.
  3. Use a helper to round up: 1 << (32 - Integer.numberOfLeadingZeros(n - 1)).

Example fix

// before
conf.put(Config.TOPOLOGY_TRANSFER_BUFFER_SIZE, 3000);
// after
conf.put(Config.TOPOLOGY_TRANSFER_BUFFER_SIZE, 4096);
Defensive patterns

Strategy: validation

Validate before calling

int v = ((Number) conf.get(key)).intValue();
if (v <= 0 || (v & (v - 1)) != 0) {
    throw new IllegalStateException(key + " must be a positive power of 2, got " + v);
}

Type guard

boolean isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }

Prevention

When it happens

Trigger: Setting a config key validated by powerOf2Validator (e.g. task/transfer buffer sizes) to a value that is 0, negative, or not 2^n (e.g. 3000, 100).

Common situations: Users picking 'round number' sizes like 1000 or 4096-compatible-but-off values; copying configs with sizes from other systems; typos like 1064 instead of 1024.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of nathanmarz/storm@cdb116e942 (2026-09-12). Data as JSON: /api/errors/9db3e2f52ebf874f. Report an issue: GitHub.

Appendix: source

Thrown at storm-core/src/jvm/backtype/storm/ConfigValidation.java:103

     * Validates a power of 2.
     */
    public static Object PowerOf2Validator = new FieldValidator() {
        @Override
        public void validateField(String name, Object o) throws IllegalArgumentException {
            if (o == null) {
                // A null value is acceptable.
                return;
            }
            final long i;
            if (o instanceof Number &&
                    (i = ((Number)o).longValue()) == ((Number)o).doubleValue())
            {
                // Test whether the integer is a power of 2.
                if (i > 0 && (i & (i-1)) == 0) {
                    return;
                }
            }
            throw new IllegalArgumentException("Field " + name + " must be a power of 2.");
        }
    };
}

View on GitHub (pinned to cdb116e942)