{"record":{"id":"09ee6209ebb4519d","repo":"elastic/elasticsearch","slug":"number-must-be-a-value-between-0-and-65535","errorCode":null,"errorMessage":"number [{}] must be a value between 0 and 65535","messagePattern":"number \\[(.+?)\\] must be a value between 0 and 65535","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CommunityIdProcessor.java","lineNumber":261,"sourceCode":"                flow.icmpCode = parseIntFromObjectOrString(icmpCode, \"icmp code\");\n            }\n        }\n\n        return flow;\n    }\n\n    @Override\n    public String getType() {\n        return TYPE;\n    }\n\n    /**\n     * Converts an integer in the range of an unsigned 16-bit integer to a big-endian byte pair\n     */\n    // visible for testing\n    static byte[] toUint16(int num) {\n        if (num < 0 || num > 65535) {\n            throw new IllegalStateException(\"number [\" + num + \"] must be a value between 0 and 65535\");\n        }\n        return new byte[] { (byte) (num >> 8), (byte) num };\n    }\n\n    /**\n     * Attempts to coerce an object to an integer\n     */\n    private static int parseIntFromObjectOrString(Object o, String fieldName) {\n        if (o == null) {\n            return 0;\n        } else if (o instanceof Number number) {\n            return number.intValue();\n        } else if (o instanceof String string) {\n            try {\n                return Integer.parseInt(string);\n            } catch (NumberFormatException e) {\n                // fall through to IllegalArgumentException below\n            }","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CommunityIdProcessor.java#L243-L279","documentation":"CommunityIdProcessor.toUint16 throws IllegalStateException (not IllegalArgumentException) when the supplied seed is < 0 or > 65535 — i.e. outside the unsigned-16-bit range used for the community-id hash seed. Used by the static apply(...) helpers; the pipeline Factory separately rejects out-of-range seeds at processor-creation time with a clearer config error.","triggerScenarios":"Calling CommunityIdProcessor.apply(..., seed) directly with seed < 0 or > 65535. The instance pipeline path stores the seed as a byte[] at construction time and never reaches toUint16 at runtime, so this throw is a programmatic-API-only failure.","commonSituations":"Custom wrappers or tests passing an unchecked int seed; downstream code deriving seed from a hash without masking to 16 bits; refactoring that bypasses the Factory validation.","solutions":["Mask the caller-provided seed to 16 bits before calling apply, e.g. seed &= 0xFFFF after rejecting negatives.","Pre-validate seed is in [0,65535] and throw a domain-meaningful error before calling apply.","Prefer constructing a CommunityIdProcessor via its Factory (which performs the same range check at config time) over the static apply API.","Catch IllegalStateException separately if you must accept arbitrary seed inputs."],"exampleFix":"// before — unchecked seed\n//   String id = CommunityIdProcessor.apply(src, dst, iana, t, sp, dp, it, ic, seed);\n//\n// after — validate / clamp before calling\n//   if (seed < 0 || seed > 65535) throw new IllegalArgumentException(\"seed out of range: \" + seed);\n//   String id = CommunityIdProcessor.apply(src, dst, iana, t, sp, dp, it, ic, seed);","handlingStrategy":"validation","validationCode":"boolean isValidSeed(int seed) { return seed >= 0 && seed <= 65535; }","typeGuard":null,"tryCatchPattern":"try {\n    byte[] seed = CommunityIdProcessor.toUint16(value);\n} catch (IllegalStateException e) {\n    // caller supplied an out-of-range seed; reject before hashing\n    throw new IllegalArgumentException(\"seed out of range: \" + value, e);\n}","preventionTips":["Always validate seed is in [0,65535] before calling apply or toUint16.","Prefer the pipeline Factory path — it performs the same check at processor creation with a clearer error.","If your seed originates from a wider hash, mask to 16 bits: seed &= 0xFFFF."],"tags":["ingest","community-id","seed","range-check","api"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}