openjdk/jdk · error · IllegalArgumentException

source output dir not set

Error message

source output dir not set

What it means

IllegalArgumentException from GenStubs.run when the output directory is null — generated stub sources are written through the JavaFileManager at StandardLocation.SOURCE_OUTPUT, which must be bound to a real directory. Pure precondition check on the API contract.

Source

Thrown at make/langtools/tools/genstubs/GenStubs.java:127

                sourcepath = iter.next();
            else if (arg.startsWith("-"))
                throw new IllegalArgumentException(arg);
            else {
                classes.add(arg);
                while (iter.hasNext())
                    classes.add(iter.next());
            }
        }

        return run(sourcepath, outdir, classes);
    }

    public boolean run(String sourcepath, File outdir, List<String> classes) {
        //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes);
        if (sourcepath == null)
            throw new IllegalArgumentException("sourcepath not set");
        if (outdir == null)
            throw new IllegalArgumentException("source output dir not set");

        JavacTool tool = JavacTool.create();
        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);

        try {
            fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir));
            fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath));
            List<JavaFileObject> files = new ArrayList<JavaFileObject>();
            for (String c: classes) {
                JavaFileObject fo = fm.getJavaFileForInput(
                        StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE);
                if (fo == null)
                    error("class not found: " + c);
                else
                    files.add(fo);
            }

            JavacTask t = tool.getTask(null, fm, null, null, null, files);

View on GitHub (pinned to 88dfb74bbe)

Solutions

  1. Set the destdir attribute (Ant) or -s option (CLI) to an existing, writable directory.
  2. Null-check and default the outdir in custom driver code before calling run().

Example fix

<!-- before -->
<genstubs srcdir="${src}"/>

<!-- after -->
<genstubs srcdir="${src}" destdir="${build.gensrc}"/>
Defensive patterns

Strategy: validation

Validate before calling

// guard the precondition before calling run()
Objects.requireNonNull(outdir, "source output dir not set");
if (!outdir.exists() && !outdir.mkdirs())
    throw new IllegalArgumentException("cannot create output dir: " + outdir);
if (!outdir.canWrite())
    throw new IllegalArgumentException("output dir not writable: " + outdir);

Try / catch

try {
    genStubs.run(sourcepath, outdir, classes);
} catch (IllegalArgumentException e) {
    throw new IllegalStateException("GenStubs misconfigured: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: Invoking run() with a null outdir — e.g. the Ant task's destdir attribute missing, or the CLI run without -s — after the sourcepath check already passed.

Common situations: Custom wrappers around GenStubs computing outdir from a property that was never set (returns null instead of a File).

Related errors


AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14). Data as JSON: /api/errors/99faa7f838903f37. Report an issue: GitHub.