{"record":{"id":"532b32b65e4bf7f6","repo":"chinabugotech/hutool","slug":"error-machine-number","errorCode":null,"errorMessage":"Error Machine number!","messagePattern":"Error Machine number!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"hutool-bloomFilter/src/main/java/cn/hutool/bloomfilter/filter/AbstractFilter.java","lineNumber":60,"sourceCode":"\n\t/**\n\t * 初始化\n\t *\n\t * @param maxValue 最大值\n\t * @param machineNum 机器位数\n\t */\n\tpublic void init(long maxValue, int machineNum) {\n\t\tthis.size = Assert.checkBetween(maxValue, 1, Integer.MAX_VALUE);\n\t\tfinal int capacity = (int) ((this.size + machineNum - 1) / machineNum);\n\t\tswitch (machineNum) {\n\t\tcase BitMap.MACHINE32:\n\t\t\tbm = new IntMap(capacity);\n\t\t\tbreak;\n\t\tcase BitMap.MACHINE64:\n\t\t\tbm = new LongMap(capacity);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tthrow new RuntimeException(\"Error Machine number!\");\n\t\t}\n\t}\n\n\t@Override\n\tpublic boolean contains(String str) {\n\t\treturn bm.contains(Math.abs(hash(str)));\n\t}\n\n\t@Override\n\tpublic boolean add(String str) {\n\t\tfinal long hash = Math.abs(hash(str));\n\t\tif (bm.contains(hash)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tbm.add(hash);\n\t\treturn true;\n\t}","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-bloomFilter/src/main/java/cn/hutool/bloomfilter/filter/AbstractFilter.java#L42-L78","documentation":"Thrown by the bloom filter's AbstractFilter.init when the supplied machineNum is neither BitMap.MACHINE32 (32) nor BitMap.MACHINE64 (64). The value selects whether the underlying bit storage uses int[] (32-bit cells) or long[] (64-bit cells); any other value leaves the bm field unassigned, so it is rejected outright as a RuntimeException. This is a configuration error, not a data error.","triggerScenarios":"Constructing any filter subclass (DefaultFilter, FNVFilter, etc.) or calling init(maxValue, machineNum) with a machineNum other than 32 or 64. Custom subclasses that pass through a computed or default value that happens to fall outside {32,64} also trigger it.","commonSituations":"Passing a literal like 16 or 128 expecting more/less granularity; copying a code sample that hard-coded a wrong constant; upgrading hutool and assuming the machine width tracks the JVM (it does not — it is a fixed enum-like int).","solutions":["Pass BitMap.MACHINE32 (32) for int-cell storage or BitMap.MACHINE64 (64) for long-cell storage; never invent other values.","If you only care about default behavior, use the constructor that omits machineNum so DEFAULT_MACHINE_NUM (MACHINE32) is applied.","Guard custom callers: validate machineNum in {32,64} before constructing the filter."],"exampleFix":"// before\nnew DefaultFilter(1_000_000, 16);\n// after\nimport cn.hutool.bloomfilter.bitMap.BitMap;\nnew DefaultFilter(1_000_000, BitMap.MACHINE64);","handlingStrategy":"validation","validationCode":"if (machineNum != BitMap.MACHINE32 && machineNum != BitMap.MACHINE64) {\n    throw new IllegalArgumentException(\"machineNum must be 32 or 64, got \" + machineNum);\n}","typeGuard":"static boolean validMachine(int m) { return m == BitMap.MACHINE32 || m == BitMap.MACHINE64; }","tryCatchPattern":null,"preventionTips":["Always reference BitMap.MACHINE32 / MACHINE64 constants, never literals.","Use the constructor overload that defaults to MACHINE32 when you have no preference."],"tags":["bloom-filter","config","argument-validation"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}