greenrobot/greenDAO · error · IOException
does not exist. This check is to prevent accidental file…
Error message
does not exist. This check is to prevent accidental file generation into a wrong path.
What it means
DaoGenerator.toFileForceExists verifies that the target output file already exists before overwriting it. This deliberate check prevents accidentally generating Java source into a wrong path (e.g. because outDir is misconfigured), since generator output files should always overwrite previously generated files that already exist.
Solutions
- Create the target file (or its directory) before running the generator, e.g. new File(outDir, ".../FooDao.java").getParentFile().mkdirs() plus an empty file for the first entity.
- Fix the outDir/baseProjectDir arguments so they point at the real existing source tree.
- Run the generator once after manually creating the expected path structure; subsequent runs will overwrite.
- In CI, check out or generate the directory skeleton before invoking the code generator step.
Example fix
// before
ew DaoGenerator().generateAll(schema, "app/src-gen", null, null); // dir may not exist
// after
File dir = new File("app/src-gen");
dir.mkdirs();
new File(dir, "com/example/AppDao.java").createNewFile(); // first file must exist
new DaoGenerator().generateAll(schema, "app/src-gen", null, null); Defensive patterns
Strategy: validation
Validate before calling
File f = new File(expectedOutPath);
if (!f.exists()) {
f.getParentFile().mkdirs();
f.createNewFile();
} Try / catch
try {
new DaoGenerator().generateAll(schema, outDir, outDirTest, baseDir);
} catch (IOException e) {
if (e.getMessage().contains("does not exist. This check")) {
throw new IllegalStateException("Output file missing — outDir is wrong or empty; fix generateAll args: " + e.getMessage(), e);
}
throw e;
} Prevention
- Run the generator at least once against a scaffolded source tree before automating it
- Verify outDir points at the real existing source root
- In CI, create the expected path skeleton before the codegen step
- Keep outDir as a checked constant, not ad-hoc strings
When it happens
Trigger: Calling generator.generateAll(schema, outDir, outDirTest, baseProjectDir) with an outDir/filename pointing at a file that does not exist yet — e.g. wrong package path, outDir pointing to an empty directory, or running before the project structure was created.
Common situations: Fresh checkout where target/generated-sources or src-gen was never created; outDir string typo or missing trailing path components; moving the schema package and forgetting to create the destination directories; CI environments with clean workspaces.
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
- No DAO registered for
- Could not init DAOConfig
- Duplicate property ordinals
- Property already defined:
- Protobuf entities do not support relations, currently
AI-assisted analysis of greenrobot/greenDAO@0bbb338e17 (2026-09-08).
Data as JSON: /api/errors/ba5e88de739b5948.
Report an issue: GitHub.
Appendix: source
Thrown at DaoGenerator/src/org/greenrobot/greendao/generator/DaoGenerator.java:155
Map<String, Object> additionalObjectsForTemplate = new HashMap<>();
additionalObjectsForTemplate.put("contentProvider", contentProvider);
generate(templateContentProvider, outDirFile, entity.getJavaPackage(), entity.getClassName()
+ "ContentProvider", schema, entity, additionalObjectsForTemplate);
}
}
generate(templateDaoMaster, outDirFile, schema.getDefaultJavaPackageDao(),
schema.getPrefix() + "DaoMaster", schema, null);
generate(templateDaoSession, outDirFile, schema.getDefaultJavaPackageDao(),
schema.getPrefix() + "DaoSession", schema, null);
long time = System.currentTimeMillis() - start;
System.out.println("Processed " + entities.size() + " entities in " + time + "ms");
}
protected File toFileForceExists(String filename) throws IOException {
File file = new File(filename);
if (!file.exists()) {
throw new IOException(filename
+ " does not exist. This check is to prevent accidental file generation into a wrong path.");
}
return file;
}
private void generate(Template template, File outDirFile, String javaPackage, String javaClassName, Schema schema,
Entity entity) throws Exception {
generate(template, outDirFile, javaPackage, javaClassName, schema, entity, null);
}
private void generate(Template template, File outDirFile, String javaPackage, String javaClassName, Schema schema,
Entity entity, Map<String, Object> additionalObjectsForTemplate) throws Exception {
Map<String, Object> root = new HashMap<>();
root.put("schema", schema);
root.put("entity", entity);
if (additionalObjectsForTemplate != null) {
root.putAll(additionalObjectsForTemplate);
}View on GitHub (pinned to 0bbb338e17)