{"record":{"id":"9db3e2f52ebf874f","repo":"nathanmarz/storm","slug":"field-name-must-be-a-power-of-2","errorCode":null,"errorMessage":"Field ${name} must be a power of 2.","messagePattern":"Field (.+?) must be a power of 2\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"storm-core/src/jvm/backtype/storm/ConfigValidation.java","lineNumber":103,"sourceCode":"     * Validates a power of 2.\n     */\n    public static Object PowerOf2Validator = new FieldValidator() {\n        @Override\n        public void validateField(String name, Object o) throws IllegalArgumentException {\n            if (o == null) {\n                // A null value is acceptable.\n                return;\n            }\n            final long i;\n            if (o instanceof Number &&\n                    (i = ((Number)o).longValue()) == ((Number)o).doubleValue())\n            {\n                // Test whether the integer is a power of 2.\n                if (i > 0 && (i & (i-1)) == 0) {\n                    return;\n                }\n            }\n            throw new IllegalArgumentException(\"Field \" + name + \" must be a power of 2.\");\n        }\n    };\n}\n","sourceCodeStart":85,"sourceCodeEnd":107,"githubUrl":"https://github.com/nathanmarz/storm/blob/cdb116e942666973bc4eaa0df098d5bab82739e7/storm-core/src/jvm/backtype/storm/ConfigValidation.java#L85-L107","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Change the value to the nearest power of 2 (e.g. 1024, 4096, 65536).","Check which key failed and its documented constraints.","Use a helper to round up: 1 << (32 - Integer.numberOfLeadingZeros(n - 1))."],"exampleFix":"// before\nconf.put(Config.TOPOLOGY_TRANSFER_BUFFER_SIZE, 3000);\n// after\nconf.put(Config.TOPOLOGY_TRANSFER_BUFFER_SIZE, 4096);","handlingStrategy":"validation","validationCode":"int v = ((Number) conf.get(key)).intValue();\nif (v <= 0 || (v & (v - 1)) != 0) {\n    throw new IllegalStateException(key + \" must be a positive power of 2, got \" + v);\n}","typeGuard":"boolean isPowerOfTwo(int n) { return n > 0 && (n & (n - 1)) == 0; }","tryCatchPattern":null,"preventionTips":["Pick buffer/worker sizes from the power-of-2 ladder (1024, 4096, 8192, ...).","Add a startup assertion validating all size-related conf keys.","Document the constraint next to any custom defaults."],"tags":["config-validation","power-of-two","storm"],"backgroundTag":"invalid-config-value","analyzedSha":"cdb116e942666973bc4eaa0df098d5bab82739e7","analyzedAt":"2026-09-12T14:30:00.714Z","contentChangedAt":"2026-09-12T14:30:00.714Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}