{"record":{"id":"7bb87800426f45a3","repo":"apache/hadoop","slug":"input-array-can-not-be-null-7bb878","errorCode":null,"errorMessage":"Input array can not be null","messagePattern":"Input array can not be null","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightLinkedSet.java","lineNumber":218,"sourceCode":"   * link list, don't worry about hashtable - faster version of the parent\n   * method.\n   */\n  @Override\n  public List<T> pollAll() {\n    List<T> retList = new ArrayList<T>(size);\n    while (head != null) {\n      retList.add(head.element);\n      head = head.after;\n    }\n    this.clear();\n    return retList;\n  }\n\n  @Override\n  @SuppressWarnings(\"unchecked\")\n  public <U> U[] toArray(U[] a) {\n    if (a == null) {\n      throw new NullPointerException(\"Input array can not be null\");\n    }\n    if (a.length < size) {\n      a = (U[]) java.lang.reflect.Array.newInstance(a.getClass()\n          .getComponentType(), size);\n    }\n    int currentIndex = 0;\n    DoubleLinkedElement<T> current = head;\n    while (current != null) {\n      T curr = current.element;\n      a[currentIndex++] = (U) curr;\n      current = current.after;\n    }\n    return a;\n  }\n\n  @Override\n  public Iterator<T> iterator() {\n    return new LinkedSetIterator();","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/util/LightWeightLinkedSet.java#L200-L236","documentation":"LightWeightLinkedSet.toArray(U[] a) mirrors the parent class behavior: an explicit NullPointerException with 'Input array can not be null' when the destination array is null, per the java.util contract. The walk then follows the linked list (insertion order), so only the null array - not ordering - can trigger this error.","triggerScenarios":"set.toArray(null) or passing a nullable array variable to toArray on a LightWeightLinkedSet.","commonSituations":"Same as the HashSet variant: optional/lazily-created array parameters, generic copy utilities, mocks returning null arrays.","solutions":["Pass a typed empty array: set.toArray(new T[0]).","Null-check and default the variable before the call.","Fall back to the no-arg toArray() when Object[] is acceptable."],"exampleFix":"// before\nT[] out = set.toArray(arrOrNull);\n\n// after\nT[] out = set.toArray(arrOrNull != null ? arrOrNull : newArrayInstance(size));","handlingStrategy":"validation","validationCode":"U[] dest = (a != null) ? a : (U[]) java.lang.reflect.Array.newInstance(componentType, set.size());\nU[] result = set.toArray(dest);","typeGuard":"static <U> boolean isUsableArray(U[] a) { return a != null; } // guard before toArray()","tryCatchPattern":null,"preventionTips":["Never pass nullable arrays; default to a typed zero-length array.","Prefer set.toArray(new T[0]) idiom in code review checklists.","For ordered output remember toArray preserves insertion order of the linked set."],"tags":["null-safety","toarray","null-pointer","linked-set"],"backgroundTag":"null-argument-rejected","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}