{"record":{"id":"a52b3a6d7750f71d","repo":"apache/hadoop","slug":"filters-cannot-be-or-ed","errorCode":null,"errorMessage":"filters cannot be or-ed","messagePattern":"filters cannot be or-ed","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java","lineNumber":169,"sourceCode":"      if(!bits.get(h[i])) {\n        return false;\n      }\n    }\n    return true;\n  }\n\n  @Override\n  public void not() {\n    bits.flip(0, vectorSize);\n  }\n\n  @Override\n  public void or(Filter filter) {\n    if(filter == null\n        || !(filter instanceof BloomFilter)\n        || filter.vectorSize != this.vectorSize\n        || filter.nbHash != this.nbHash) {\n      throw new IllegalArgumentException(\"filters cannot be or-ed\");\n    }\n    bits.or(((BloomFilter) filter).bits);\n  }\n\n  @Override\n  public void xor(Filter filter) {\n    if(filter == null\n        || !(filter instanceof BloomFilter)\n        || filter.vectorSize != this.vectorSize\n        || filter.nbHash != this.nbHash) {\n      throw new IllegalArgumentException(\"filters cannot be xor-ed\");\n    }\n    bits.xor(((BloomFilter) filter).bits);\n  }\n\n  @Override\n  public String toString() {\n    return bits.toString();","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/BloomFilter.java#L151-L187","documentation":"BloomFilter.or(Filter) unions another filter's bits into this one. Like and() and xor(), it requires the operand to be a non-null BloomFilter with exactly the same vectorSize and nbHash; a bit-union only makes sense between filters over the same bit space and hash functions, so anything else throws IllegalArgumentException('filters cannot be or-ed').","triggerScenarios":"filterA.or(filterB) where the two filters were constructed with different vectorSize or nbHash; filterA.or(null); filterA.or(new Filter subclass) that is not a BloomFilter.","commonSituations":"Aggregating per-block or per-node bloom filters (a classic union use) where producers were configured with different sizes; rolling upgrades changing the default vector size between filter producers; hard-coded constructor literals drifting apart between classes.","solutions":["Create all union participants with the same constructor parameters — centralize vectorSize/nbHash/hashType in shared constants.","Validate shape equality before calling or() and drop/rebuild mismatched filters.","If union participants legitimately differ, add all underlying elements into one uniformly shaped filter instead.","Catch IllegalArgumentException during aggregation to isolate the misconfigured producer."],"exampleFix":"// before\nBloomFilter merged = new BloomFilter(VECTOR_SIZE, HASH_COUNT, Hash.MURMUR_HASH);\nfor (BloomFilter f : shardFilters) { // one shard used VECTOR_SIZE 512\n  merged.or(f); // throws: filters cannot be or-ed\n}\n\n// after\nfor (BloomFilter f : shardFilters) {\n  if (f.vectorSize == merged.vectorSize && f.nbHash == merged.nbHash) {\n    merged.or(f);\n  }\n}","handlingStrategy":"validation","validationCode":"for (BloomFilter f : shardFilters) {\n  if (f == null || f.vectorSize != merged.vectorSize\n      || f.nbHash != merged.nbHash) {\n    LOG.warn(\"Skipping shape-mismatched filter\");\n    continue;\n  }\n  merged.or(f);\n}","typeGuard":"static boolean sameShape(BloomFilter a, BloomFilter b) {\n  return b != null && b.vectorSize == a.vectorSize && b.nbHash == a.nbHash;\n}","tryCatchPattern":"try {\n  merged.or(f);\n} catch (IllegalArgumentException e) {\n  throw new IllegalStateException(\"Union aborted: producer filter shape=\"\n      + f.vectorSize + \"/\" + f.nbHash, e);\n}","preventionTips":["Centralize vectorSize/nbHash/hashType in one config used by every producer.","Validate shape before union when aggregating remote or persisted filters.","Pin filter shape in metadata alongside serialized filters."],"tags":["bloom-filter","incompatible-parameters","merge","hadoop-common"],"backgroundTag":"bloom-filter-incompatible","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}