{"record":{"id":"ba5e88de739b5948","repo":"greenrobot/greenDAO","slug":"does-not-exist-this-check-is-to-prevent-accidenta","errorCode":null,"errorMessage":"does not exist. This check is to prevent accidental file generation into a wrong path.","messagePattern":"does not exist\\. This check is to prevent accidental file generation into a wrong path\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"DaoGenerator/src/org/greenrobot/greendao/generator/DaoGenerator.java","lineNumber":155,"sourceCode":"                Map<String, Object> additionalObjectsForTemplate = new HashMap<>();\n                additionalObjectsForTemplate.put(\"contentProvider\", contentProvider);\n                generate(templateContentProvider, outDirFile, entity.getJavaPackage(), entity.getClassName()\n                        + \"ContentProvider\", schema, entity, additionalObjectsForTemplate);\n            }\n        }\n        generate(templateDaoMaster, outDirFile, schema.getDefaultJavaPackageDao(),\n                schema.getPrefix() + \"DaoMaster\", schema, null);\n        generate(templateDaoSession, outDirFile, schema.getDefaultJavaPackageDao(),\n                schema.getPrefix() + \"DaoSession\", schema, null);\n\n        long time = System.currentTimeMillis() - start;\n        System.out.println(\"Processed \" + entities.size() + \" entities in \" + time + \"ms\");\n    }\n\n    protected File toFileForceExists(String filename) throws IOException {\n        File file = new File(filename);\n        if (!file.exists()) {\n            throw new IOException(filename\n                    + \" does not exist. This check is to prevent accidental file generation into a wrong path.\");\n        }\n        return file;\n    }\n\n    private void generate(Template template, File outDirFile, String javaPackage, String javaClassName, Schema schema,\n                          Entity entity) throws Exception {\n        generate(template, outDirFile, javaPackage, javaClassName, schema, entity, null);\n    }\n\n    private void generate(Template template, File outDirFile, String javaPackage, String javaClassName, Schema schema,\n                          Entity entity, Map<String, Object> additionalObjectsForTemplate) throws Exception {\n        Map<String, Object> root = new HashMap<>();\n        root.put(\"schema\", schema);\n        root.put(\"entity\", entity);\n        if (additionalObjectsForTemplate != null) {\n            root.putAll(additionalObjectsForTemplate);\n        }","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/greenrobot/greenDAO/blob/0bbb338e17c4cf28aba5aae62d42f73f50186157/DaoGenerator/src/org/greenrobot/greendao/generator/DaoGenerator.java#L137-L173","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\new DaoGenerator().generateAll(schema, \"app/src-gen\", null, null); // dir may not exist\n// after\nFile dir = new File(\"app/src-gen\");\ndir.mkdirs();\nnew File(dir, \"com/example/AppDao.java\").createNewFile(); // first file must exist\nnew DaoGenerator().generateAll(schema, \"app/src-gen\", null, null);","handlingStrategy":"validation","validationCode":"File f = new File(expectedOutPath);\nif (!f.exists()) {\n    f.getParentFile().mkdirs();\n    f.createNewFile();\n}","typeGuard":null,"tryCatchPattern":"try {\n    new DaoGenerator().generateAll(schema, outDir, outDirTest, baseDir);\n} catch (IOException e) {\n    if (e.getMessage().contains(\"does not exist. This check\")) {\n        throw new IllegalStateException(\"Output file missing — outDir is wrong or empty; fix generateAll args: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["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"],"tags":["greendao","code-generation","file-not-found"],"backgroundTag":"file-not-found","analyzedSha":"0bbb338e17c4cf28aba5aae62d42f73f50186157","analyzedAt":"2026-09-08T03:22:36.050Z","contentChangedAt":"2026-09-08T03:22:36.050Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}