{"record":{"id":"320289abd98ed1bb","repo":"apache/hadoop","slug":"null-argument-passed-in-equal","errorCode":null,"errorMessage":"null argument passed in equal().","messagePattern":"null argument passed in equal\\(\\)\\.","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/EnumSetWritable.java","lineNumber":163,"sourceCode":"        if (this.elementType == null)\n          throw new UnsupportedOperationException(\n              \"Unable to serialize empty EnumSet with no element type provided.\");\n        WritableUtils.writeString(out, this.elementType.getName());\n      }\n      for (int i = 0; i < length; i++) {\n        ObjectWritable.writeObject(out, array[i], array[i].getClass(), conf);\n      }\n    }\n  }\n\n  /**\n   * Returns true if <code>o</code> is an EnumSetWritable with the same value,\n   * or both are null.\n   */\n  @Override\n  public boolean equals(Object o) {\n    if (o == null) {\n      throw new IllegalArgumentException(\"null argument passed in equal().\");\n    }\n\n    if (!(o instanceof EnumSetWritable))\n      return false;\n\n    EnumSetWritable<?> other = (EnumSetWritable<?>) o;\n\n    if (this == o || (this.value == other.value))\n      return true;\n    if (this.value == null) // other.value must not be null if we reach here\n      return false;\n\n    return this.value.equals(other.value);\n  }\n\n  /**\n   * Returns the class of all the elements of the underlying EnumSetWriable. It\n   * may return null.","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/io/EnumSetWritable.java#L145-L181","documentation":"EnumSetWritable.equals() deliberately violates the standard equals contract by throwing IllegalArgumentException on a null argument instead of returning false. Any caller that follows the normal Java convention of comparing possibly-null references (HashMap lookups, Objects.equals expectations) will get an exception instead of false.","triggerScenarios":"writable.equals(null); collections APIs that probe with null (e.g. list.contains(null), map.get-like scans); assertion libraries comparing against an expected null.","commonSituations":"Putting EnumSetWritable into ArrayList/HashSet and calling contains(null); comparing a decoded value to a null expected value in tests; generic pipeline code doing value.equals(current) where current may be null.","solutions":["Null-check before comparing: if (o != null && writable.equals(o)).","Reverse the comparison when possible: pass the writable as the argument to a null-safe equals.","Use java.util.Objects.equals carefully — it calls a.equals(b), so guard the EnumSetWritable side being non-null and the argument being non-null."],"exampleFix":"// before\nboolean same = esw.equals(maybeNull); // throws when maybeNull == null\n\n// after\nboolean same = maybeNull != null && esw.equals(maybeNull);","handlingStrategy":"validation","validationCode":"boolean same = (maybeNull instanceof EnumSetWritable) && esw.equals(maybeNull);","typeGuard":"static boolean safeEquals(EnumSetWritable<?> a, Object b) {\n  return b != null && a.equals(b);\n}","tryCatchPattern":null,"preventionTips":["Null-check arguments before equals() — this class throws instead of returning false.","Be careful with contains(null)/indexOf(null) on collections holding EnumSetWritable."],"tags":["hadoop","serialization","writable","equals-contract","null-check"],"backgroundTag":"null-argument-validation","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}