apache/iceberg · error · NoSuchElementException
No more scan tasks available
Error message
No more scan tasks available
What it means
Standard NoSuchElementException thrown by the FileScanTaskIterator's next() when next() is called after the iterator is exhausted. It exists to give a clearer message than the default no-args NoSuchElementException.
Solutions
- Guard every next() call with hasNext()
- Use a for-each loop instead of manual iterator calls
- Re-acquire the iterator (re-run tasks()) if you need to iterate again
- Don't store/iterate the iterator after consuming it
Example fix
// before
CloseableIterator<FileScanTask> it = tasks.iterator();
FileScanTask t1 = it.next();
FileScanTask t2 = it.next(); // throws when exhausted
// after
while (it.hasNext()) {
FileScanTask t = it.next();
}
// or: for (FileScanTask t : tasks) { ... } Defensive patterns
Strategy: type-guard
Validate before calling
// always check before advancing
if (iterator.hasNext()) { iterator.next(); } Type guard
boolean safeNext(Iterator<FileScanTask> it) {
if (!it.hasNext()) return false;
it.next();
return true;
} Try / catch
try { task = it.next(); } catch (NoSuchElementException e) {
task = null; // or break the loop
} Prevention
- Always gate next() with hasNext()
- Prefer for-each loops over manual iterators
- Never reuse an exhausted iterator; call tasks() again
When it happens
Trigger: Calling next() on a ScanTaskIterable iterator without a preceding true hasNext() — e.g. looping twice over a single-element iterator, or calling next() twice past the end.
Common situations: Bugs in code that iterates scan tasks without hasNext guards; consumer pipelines that over-advance iterators; reusing exhausted iterators instead of requesting new ones.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12).
Data as JSON: /api/errors/4e95e38763595c80.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/org/apache/iceberg/rest/ScanTaskIterable.java:270
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
shutdown.set(true);
}
}
RuntimeException workerFailure = failure.get();
if (workerFailure != null) {
throw workerFailure;
}
return hasNext;
}
@Override
public FileScanTask next() {
if (!hasNext()) {
throw new NoSuchElementException("No more scan tasks available");
}
FileScanTask result = nextTask;
nextTask = null;
return result;
}
@Override
public void close() {
shutdown.set(true);
LOG.info(
"ScanTasksIterator is closing. Clearing {} queued tasks and {} plan tasks.",
taskQueue.size(),
planTasks.size());
taskQueue.clear();
planTasks.clear();
}
}
}View on GitHub (pinned to 86d9c8fc54)