{"record":{"id":"f4e28e22ca9a8483","repo":"openjdk/jdk","slug":"genstubs-failed","errorCode":null,"errorMessage":"genstubs failed","messagePattern":"genstubs failed","errorType":"exception","errorClass":"BuildException","httpStatus":null,"severity":"error","filePath":"make/langtools/tools/anttasks/GenStubsTask.java","lineNumber":116,"sourceCode":"//            System.err.println(\"Ant.execute: srcDir \" + srcDir);\n//            System.err.println(\"Ant.execute: destDir \" + destDir);\n//            System.err.println(\"Ant.execute: files \" + Arrays.asList(files));\n\n        files = filter(srcDir, destDir, files);\n        if (files.length == 0)\n            return;\n        System.out.println(\"Generating \" + files.length + \" stub files to \" + destDir);\n\n        List<String> classNames = new ArrayList<>();\n        for (String file: files) {\n            classNames.add(file.replaceAll(\".java$\", \"\").replace('/', '.'));\n        }\n\n        if (!fork) {\n            GenStubs m = new GenStubs();\n            boolean ok = m.run(srcDir.getPath(), destDir, classNames);\n            if (!ok)\n                throw new BuildException(\"genstubs failed\");\n        } else {\n            List<String> cmd = new ArrayList<>();\n            String java_home = System.getProperty(\"java.home\");\n            cmd.add(new File(new File(java_home, \"bin\"), \"java\").getPath());\n            if (classpath != null)\n                cmd.add(\"-Xbootclasspath/p:\" + classpath);\n            cmd.add(GenStubs.class.getName());\n            cmd.add(\"-sourcepath\");\n            cmd.add(srcDir.getPath());\n            cmd.add(\"-s\");\n            cmd.add(destDir.getPath());\n            cmd.addAll(classNames);\n            //System.err.println(\"GenStubs exec \" + cmd);\n            ProcessBuilder pb = new ProcessBuilder(cmd);\n            pb.redirectErrorStream(true);\n            try {\n                Process p = pb.start();\n                try (BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()))) {","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/make/langtools/tools/anttasks/GenStubsTask.java#L98-L134","documentation":"Thrown by the GenStubs Ant task when GenStubs.run() returns false in in-process mode. GenStubs parses JDK source files with the javac API and emits minimal 'stub' source files (signatures with throw new RuntimeException()) used to compile langtools against future-JDK APIs; failure means the internal compilation/translation step failed.","triggerScenarios":"Invoking the genstubs target with fork=false (default) while any class listed in the file filter has a syntax error, references types missing from the sourcepath, or when the javac TreeScanner translation aborts (run() catches Throwable, prints a stack trace, and returns false).","commonSituations":"Building langtools against an in-progress JDK source tree where an API being stubbed changed shape; wrong srcDir attribute pointing at incomplete source; JDK version mismatch between the bootjavac and the source being parsed.","solutions":["Look at the stack trace GenStubs prints to stdout right before returning false — it names the class and the parse/translate failure.","Confirm the task's srcDir and destDir attributes and that every filtered .java file exists under srcDir.","Update or remove the offending classes from the genstubs include list so they are no longer stubbed.","As a diagnostic, set fork='true' on the task to run GenStubs in a fresh JVM with -Xbootclasspath/p:classpath, isolating it from Ant's classpath."],"exampleFix":"<!-- before -->\n<genstubs srcdir=\"${langtools.src}\" destdir=\"${build.gensrc}\" include=\"**/*.java\"/>\n\n<!-- after: restrict to the APIs that actually need stubs -->\n<genstubs srcdir=\"${langtools.src}\" destdir=\"${build.gensrc}\"\n          include=\"java/lang/**/*.java,java/util/**/*.java\"/>","handlingStrategy":"try-catch","validationCode":"// verify every class to be stubbed resolves on the sourcepath before running\nfor (String cn : classNames) {\n    Path f = Paths.get(srcDir, cn.replace('.', '/') + \".java\");\n    if (!Files.isReadable(f)) throw new IllegalStateException(\"missing source: \" + f);\n}","typeGuard":null,"tryCatchPattern":"try {\n    new GenStubs().run(sourcepath, outdir, classNames);\n} catch (Throwable t) {\n    // GenStubs.run() itself catches Throwable and returns false;\n    // treat any stack trace printed by it as the authoritative diagnosis\n    logger.error(\"genstubs failed for \" + classNames, t);\n    throw t;\n}","preventionTips":["Pin the genstubs include list to stable, API-only packages instead of whole source trees.","Run genstubs in a clean build dir each time so partial stub output cannot accumulate.","Regenerate stubs whenever the underlying JDK source is updated, not on a stale checkout."],"tags":["ant","build","genstubs","javac","code-generation"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}