{"record":{"id":"4e06bea01ce94cd0","repo":"apache/iceberg","slug":"no-in-memory-file-found-for-location-s","errorCode":null,"errorMessage":"No in-memory file found for location: %s","messagePattern":"No in-memory file found for location: (.+?)","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/inmemory/InMemoryFileIO.java","lineNumber":61,"sourceCode":"  public Map<String, String> properties() {\n    return properties.immutableMap();\n  }\n\n  public void addFile(String location, byte[] contents) {\n    Preconditions.checkState(!closed, \"Cannot call addFile after calling close()\");\n    IN_MEMORY_FILES.put(location, contents);\n  }\n\n  public boolean fileExists(String location) {\n    return IN_MEMORY_FILES.containsKey(location);\n  }\n\n  @Override\n  public InputFile newInputFile(String location) {\n    Preconditions.checkState(!closed, \"Cannot call newInputFile after calling close()\");\n    byte[] contents = IN_MEMORY_FILES.get(location);\n    if (null == contents) {\n      throw new NotFoundException(\"No in-memory file found for location: %s\", location);\n    }\n    return new InMemoryInputFile(location, contents);\n  }\n\n  @Override\n  public OutputFile newOutputFile(String location) {\n    Preconditions.checkState(!closed, \"Cannot call newOutputFile after calling close()\");\n    return new InMemoryOutputFile(location, this);\n  }\n\n  @Override\n  public void deleteFile(String location) {\n    Preconditions.checkState(!closed, \"Cannot call deleteFile after calling close()\");\n    if (null == IN_MEMORY_FILES.remove(location)) {\n      throw new NotFoundException(\"No in-memory file found for location: %s\", location);\n    }\n  }\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/inmemory/InMemoryFileIO.java#L43-L79","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the exact location string matches what was passed to newOutputFile (same scheme, path, and no trailing differences).","Ensure the output file was actually written (createOrOverwrite() called and stream closed) before reading.","Check fileExists(location) first if presence is optional, or catch org.apache.iceberg.exceptions.NotFoundException."],"exampleFix":"// before\nInputFile in = io.newInputFile(\"mem://missing.parquet\");\n// after\nif (io instanceof InMemoryFileIO && ((InMemoryFileIO) io).fileExists(\"mem://missing.parquet\")) {\n  InputFile in = io.newInputFile(\"mem://missing.parquet\");\n}","handlingStrategy":"try-catch","validationCode":"if (!((InMemoryFileIO) io).fileExists(location)) { throw new IllegalArgumentException(\"not written: \" + location); }","typeGuard":null,"tryCatchPattern":"try {\n  InputFile in = io.newInputFile(location);\n} catch (NotFoundException e) {\n  // handle missing file: skip, create, or fail fast\n}","preventionTips":["Centralize location construction so read and write paths use identical strings.","Write-then-close before reading any in-memory file in tests.","Use fileExists checks for optional reads."],"tags":["file-io","not-found","in-memory","testing"],"backgroundTag":"file-not-found","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}