{"record":{"id":"065aea8b42410d39","repo":"apache/hadoop","slug":"undefined-selective-clearing-scheme","errorCode":null,"errorMessage":"Undefined selective clearing scheme","messagePattern":"Undefined selective clearing scheme","errorType":"validation","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java","lineNumber":230,"sourceCode":"\n    case RANDOM:\n      index = randomRemove();\n      break;\n    \n    case MINIMUM_FN:\n      index = minimumFnRemove(h);\n      break;\n    \n    case MAXIMUM_FP:\n      index = maximumFpRemove(h);\n      break;\n    \n    case RATIO:\n      index = ratioRemove(h);\n      break;\n    \n    default:\n      throw new AssertionError(\"Undefined selective clearing scheme\");\n\n    }\n\n    clearBit(index);\n  }\n\n  private int randomRemove() {\n    if (rand == null) {\n      rand = new Random();\n    }\n\n    return rand.nextInt(nbHash);\n  }\n\n  /**\n   * Chooses the bit position that minimizes the number of false negative generated.\n   * @param h The different bit positions.\n   * @return The position that minimizes the number of false negative generated.","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/bloom/RetouchedBloomFilter.java#L212-L248","documentation":"selectiveClearing switches over the four RemoveScheme constants RetouchedBloomFilter implements: RANDOM=0, MINIMUM_FN=1, MAXIMUM_FP=2, RATIO=3. Any other short hits the default branch and throws AssertionError, i.e. a broken invariant caused by the caller passing an out-of-range scheme value.","triggerScenarios":"selectiveClearing(k, (short) 4) or a negative value; scheme IDs read from a file/protocol that defines more schemes than this class supports; hand-mapping an enum to raw shorts and missing a case.","commonSituations":"Config-driven scheme selection; version skew where a producer emits a scheme this build lacks; copy-paste of magic numbers instead of the named constants.","solutions":["Always pass the named constants RemoveScheme.RANDOM / MINIMUM_FN / MAXIMUM_FP / RATIO, never raw shorts","Validate externally sourced scheme values against 0..3 (or parse into an enum) before use","Bounds-check scheme values right after deserialization"],"exampleFix":"// before\nrbf.selectiveClearing(k, schemeFromFile); // raw short: (short) 4 -> AssertionError\n\n// after\nif (schemeFromFile < RemoveScheme.RANDOM || schemeFromFile > RemoveScheme.RATIO) {\n  throw new IOException(\"invalid remove scheme: \" + schemeFromFile);\n}\nrbf.selectiveClearing(k, schemeFromFile);","handlingStrategy":"validation","validationCode":"if (scheme < RemoveScheme.RANDOM || scheme > RemoveScheme.RATIO) {\n  throw new IOException(\"invalid remove scheme: \" + scheme);\n}\nrbf.selectiveClearing(k, scheme);","typeGuard":"static boolean isValidRemoveScheme(short scheme) {\n  return scheme >= RemoveScheme.RANDOM && scheme <= RemoveScheme.RATIO;\n}","tryCatchPattern":null,"preventionTips":["Never pass raw shorts - always the RemoveScheme constants","Parse external scheme values into an enum at the boundary and reject unknowns there","Do not catch AssertionError in production code; fix the caller instead"],"tags":["hadoop","bloom-filter","java","programming-error","assertion"],"backgroundTag":"unsupported-scheme-value","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}