apache/iceberg · error · NotFoundException

No in-memory file found for location

Error message

No in-memory file found for location: %s

What it means

InMemoryFileIO.newInputFile looks up the location in its in-memory map and throws NotFoundException when no bytes were previously written under that location. This is the in-memory FileIO's equivalent of opening a nonexistent file.

Solutions

  1. Verify the exact location string matches what was passed to newOutputFile (same scheme, path, and no trailing differences).
  2. Ensure the output file was actually written (createOrOverwrite() called and stream closed) before reading.
  3. Check fileExists(location) first if presence is optional, or catch org.apache.iceberg.exceptions.NotFoundException.

Example fix

// before
InputFile in = io.newInputFile("mem://missing.parquet");
// after
if (io instanceof InMemoryFileIO && ((InMemoryFileIO) io).fileExists("mem://missing.parquet")) {
  InputFile in = io.newInputFile("mem://missing.parquet");
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (!((InMemoryFileIO) io).fileExists(location)) { throw new IllegalArgumentException("not written: " + location); }

Try / catch

try {
  InputFile in = io.newInputFile(location);
} catch (NotFoundException e) {
  // handle missing file: skip, create, or fail fast
}

Prevention

When it happens

Trigger: Calling newInputFile(location) for a location that was never created via newOutputFile(location) (and createOrOverwrite/write), or after the map entry was removed via deleteFile.

Common situations: Typos or wrong scheme in the location string; reading a file written by a different InMemoryFileIO instance (each instance has its own static map — actually shared static map, but cleared instances or test isolation issues); reading before the writer was closed/flushed in test code.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/4e06bea01ce94cd0. Report an issue: GitHub.

Appendix: source

Thrown at core/src/main/java/org/apache/iceberg/inmemory/InMemoryFileIO.java:61

  public Map<String, String> properties() {
    return properties.immutableMap();
  }

  public void addFile(String location, byte[] contents) {
    Preconditions.checkState(!closed, "Cannot call addFile after calling close()");
    IN_MEMORY_FILES.put(location, contents);
  }

  public boolean fileExists(String location) {
    return IN_MEMORY_FILES.containsKey(location);
  }

  @Override
  public InputFile newInputFile(String location) {
    Preconditions.checkState(!closed, "Cannot call newInputFile after calling close()");
    byte[] contents = IN_MEMORY_FILES.get(location);
    if (null == contents) {
      throw new NotFoundException("No in-memory file found for location: %s", location);
    }
    return new InMemoryInputFile(location, contents);
  }

  @Override
  public OutputFile newOutputFile(String location) {
    Preconditions.checkState(!closed, "Cannot call newOutputFile after calling close()");
    return new InMemoryOutputFile(location, this);
  }

  @Override
  public void deleteFile(String location) {
    Preconditions.checkState(!closed, "Cannot call deleteFile after calling close()");
    if (null == IN_MEMORY_FILES.remove(location)) {
      throw new NotFoundException("No in-memory file found for location: %s", location);
    }
  }

View on GitHub (pinned to 86d9c8fc54)