{"record":{"id":"89a457718530f67d","repo":"openjdk/jdk","slug":"sourcepath-not-set","errorCode":null,"errorMessage":"sourcepath not set","messagePattern":"sourcepath not set","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"make/langtools/tools/genstubs/GenStubs.java","lineNumber":125,"sourceCode":"                outdir = new File(iter.next());\n            else if (arg.equals(\"-sourcepath\") && iter.hasNext())\n                sourcepath = iter.next();\n            else if (arg.startsWith(\"-\"))\n                throw new IllegalArgumentException(arg);\n            else {\n                classes.add(arg);\n                while (iter.hasNext())\n                    classes.add(iter.next());\n            }\n        }\n\n        return run(sourcepath, outdir, classes);\n    }\n\n    public boolean run(String sourcepath, File outdir, List<String> classes) {\n        //System.err.println(\"run: sourcepath:\" + sourcepath + \" outdir:\" + outdir + \" classes:\" + classes);\n        if (sourcepath == null)\n            throw new IllegalArgumentException(\"sourcepath not set\");\n        if (outdir == null)\n            throw new IllegalArgumentException(\"source output dir not set\");\n\n        JavacTool tool = JavacTool.create();\n        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);\n\n        try {\n            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));\n            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));\n            List<JavaFileObject> files = new ArrayList<JavaFileObject>();\n            for (String c: classes) {\n                JavaFileObject fo = fm.getJavaFileForInput(\n                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);\n                if (fo == null)\n                    error(\"class not found: \" + c);\n                else\n                    files.add(fo);\n            }","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/make/langtools/tools/genstubs/GenStubs.java#L107-L143","documentation":"IllegalArgumentException from GenStubs.run(String sourcepath, File outdir, List<String> classes) — the entry-point contract requires a non-null sourcepath because the tool must resolve each class name to a source file via StandardLocation.SOURCE_PATH. It is a precondition check, not an I/O failure.","triggerScenarios":"Calling run() (directly or through the Ant task with fork=false) after argument parsing produced a null sourcepath — e.g. invoking GenStubs main() without -sourcepath, or passing null from a custom driver.","commonSituations":"Custom build scripts invoking GenStubs programmatically; an Ant task configuration where the srcdir attribute was omitted so its getPath() path never reached run().","solutions":["Always pass -sourcepath (CLI) or set the srcdir attribute (Ant) before generating stubs.","If calling run() from code, validate arguments before the call (see defense below)."],"exampleFix":"// before\ngenStubs.run(null, outDir, classNames);\n\n// after\ngenStubs.run(Paths.get(\"src/java.base/share/classes\").toString(), outDir, classNames);","handlingStrategy":"validation","validationCode":"// guard the precondition before calling run()\nObjects.requireNonNull(sourcepath, \"sourcepath not set\");\nif (!Files.isDirectory(Paths.get(sourcepath)))\n    throw new IllegalArgumentException(\"sourcepath does not exist: \" + sourcepath);","typeGuard":null,"tryCatchPattern":"try {\n    genStubs.run(sourcepath, outdir, classes);\n} catch (IllegalArgumentException e) {\n    // precondition violation: fix the caller, do not retry\n    throw new IllegalStateException(\"GenStubs misconfigured: \" + e.getMessage(), e);\n}","preventionTips":["Always supply -sourcepath on the GenStubs command line or srcdir in Ant.","Fail fast in wrappers: null-check arguments before delegating to run()."],"tags":["genstubs","precondition","illegal-argument","build"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}