{"record":{"id":"685dda5315ec750d","repo":"apache/hadoop","slug":"no-more-elements","errorCode":null,"errorMessage":"No more elements","messagePattern":"No more elements","errorType":"exception","errorClass":"NoSuchElementException","httpStatus":null,"severity":"error","filePath":"hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/util/Iterables.java","lineNumber":125,"sourceCode":"        if (curIter != null) {\n          curIter = null;\n        }\n\n        if (!iterators.hasNext()) {\n          return false;\n        }\n\n        curIter = iterators.next().iterator();\n      }\n      return true;\n    }\n\n    @Override\n    public T next() {\n      if (hasNext()) {\n        return curIter.next();\n      }\n      throw new NoSuchElementException(\"No more elements\");\n    }\n  }\n}\n","sourceCodeStart":107,"sourceCodeEnd":129,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-cloud-storage-project/hadoop-tos/src/main/java/org/apache/hadoop/fs/tosfs/util/Iterables.java#L107-L129","documentation":"The ConcatenatedIterator inside Iterables#concat chains multiple sub-iterables; its next() throws NoSuchElementException('No more elements') when hasNext() is false — every sub-iterator is exhausted (or all were empty). Same protocol rule as [286]: the exception signals caller misuse, specifically consuming a concatenated iterable past its end.","triggerScenarios":"Iterating the result of Iterables.concat(...) and calling next() after the final element, or assuming a non-empty chain (e.g. concat of N part-lists where every part-list came back empty) and unconditionally taking the first element.","commonSituations":"Multipart-upload part enumeration where all parts lists are empty; merging paginated object listings and forgetting the aggregate can be empty; utility code that does iterator.next() to peek instead of hasNext().","solutions":["Always gate next() with hasNext() — including when you 'know' the collection is non-empty.","Handle the empty-aggregate case explicitly before iterating (size check, isEmpty branch, or Optional-style wrapping).","Replace peek-by-next() with a hasNext()-based peek or a defensive copy you then inspect.","Unit-test the empty-input path of whatever builds the concatenated iterable."],"exampleFix":"// before\nIterator<T> it = Iterables.concat(lists).iterator();\nT only = it.next(); // NoSuchElementException when all lists empty\n\n// after\nIterable<T> all = Iterables.concat(lists);\nif (all.iterator().hasNext()) { T only = all.iterator().next(); } else { /* empty path */ }","handlingStrategy":"validation","validationCode":"Iterable<T> all = Iterables.concat(lists);\nIterator<T> it = all.iterator();\nif (it.hasNext()) { T first = it.next(); } else { /* explicit empty branch */ }","typeGuard":null,"tryCatchPattern":"try { T v = it.next(); }\ncatch (NoSuchElementException e) { /* exhausted: finish loop cleanly */ }","preventionTips":["Handle the empty-concatenation case before consuming.","Avoid peek-by-next(); use hasNext() to look ahead.","Test iterator helpers against empty and all-empty inputs."],"tags":["iterator","no-such-element-exception","concat","programming-error"],"backgroundTag":"iterator-next-past-end","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}