chinabugotech/hutool · error · RuntimeException
Error Machine number!
Error message
Error Machine number!
What it means
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.
Source
Thrown at hutool-bloomFilter/src/main/java/cn/hutool/bloomfilter/filter/AbstractFilter.java:60
/**
* 初始化
*
* @param maxValue 最大值
* @param machineNum 机器位数
*/
public void init(long maxValue, int machineNum) {
this.size = Assert.checkBetween(maxValue, 1, Integer.MAX_VALUE);
final int capacity = (int) ((this.size + machineNum - 1) / machineNum);
switch (machineNum) {
case BitMap.MACHINE32:
bm = new IntMap(capacity);
break;
case BitMap.MACHINE64:
bm = new LongMap(capacity);
break;
default:
throw new RuntimeException("Error Machine number!");
}
}
@Override
public boolean contains(String str) {
return bm.contains(Math.abs(hash(str)));
}
@Override
public boolean add(String str) {
final long hash = Math.abs(hash(str));
if (bm.contains(hash)) {
return false;
}
bm.add(hash);
return true;
}View on GitHub (pinned to 8870454b2a)
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.
Example fix
// before new DefaultFilter(1_000_000, 16); // after import cn.hutool.bloomfilter.bitMap.BitMap; new DefaultFilter(1_000_000, BitMap.MACHINE64);
Defensive patterns
Strategy: validation
Validate before calling
if (machineNum != BitMap.MACHINE32 && machineNum != BitMap.MACHINE64) {
throw new IllegalArgumentException("machineNum must be 32 or 64, got " + machineNum);
} Type guard
static boolean validMachine(int m) { return m == BitMap.MACHINE32 || m == BitMap.MACHINE64; } Prevention
- Always reference BitMap.MACHINE32 / MACHINE64 constants, never literals.
- Use the constructor overload that defaults to MACHINE32 when you have no preference.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- No method for alias: [{}]
- Bad expression '{}':{}, we find ']' but no '[' !
- Bad expression '{}':{}, we find '[' but no ']' !
- Invalid Getter or Setter name:
- Record class [] has no components
AI-assisted analysis of chinabugotech/hutool@8870454b2a (2026-08-14).
Data as JSON: /api/errors/532b32b65e4bf7f6.
Report an issue: GitHub.