{"record":{"id":"c9c4b1ba6c05de52","repo":"projectlombok/lombok","slug":"api-class-s-cannot-be-found","errorCode":null,"errorMessage":"api class %s cannot be found","messagePattern":"api class (.+?) cannot be found","errorType":"exception","errorClass":"Fail","httpStatus":null,"severity":"error","filePath":"src/core/lombok/core/PublicApiCreatorApp.java","lineNumber":132,"sourceCode":"\t\t\t}\n\t\t} finally {\n\t\t\tself.close();\n\t\t}\n\t\t\n\t\tif (toCopy.isEmpty()) {\n\t\t\tSystem.out.println(\"Not generating lombok-api.jar: No lombok api classes required!\");\n\t\t\treturn 1;\n\t\t}\n\t\t\n\t\tOutputStream out = new FileOutputStream(outFile);\n\t\tboolean success = false;\n\t\ttry {\n\t\t\tJarOutputStream jar = new JarOutputStream(out);\n\t\t\tfor (String resourceName : toCopy) {\n\t\t\t\tInputStream in = Lombok.class.getResourceAsStream(\"/\" + resourceName);\n\t\t\t\ttry {\n\t\t\t\t\tif (in == null) {\n\t\t\t\t\t\tthrow new Fail(String.format(\"api class %s cannot be found\", resourceName));\n\t\t\t\t\t}\n\t\t\t\t\twriteIntoJar(jar, resourceName, in);\n\t\t\t\t} finally {\n\t\t\t\t\tif (in != null) in.close();\n\t\t\t\t}\n\t\t\t}\n\t\t\tjar.close();\n\t\t\tout.close();\n\t\t\t\n\t\t\tSystem.out.println(\"Successfully created: \" + canonical(outFile));\n\t\t\t\n\t\t\treturn 0;\n\t\t} catch (Throwable t) {\n\t\t\ttry { out.close();} catch (Throwable ignore) {}\n\t\t\tif (!success) outFile.delete();\n\t\t\tif (t instanceof Fail) {\n\t\t\t\tSystem.err.println(t.getMessage());\n\t\t\t\treturn 1;","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/projectlombok/lombok/blob/6d6a3e9fec0a9555702561fbeb8eac836575116e/src/core/lombok/core/PublicApiCreatorApp.java#L114-L150","documentation":"PublicApiCreatorApp.writeApiJar() builds lombok's public API jar by copying known resource/class entries from the lombok jar into a new jar. When Lombok.class.getResourceAsStream() returns null for a resource name (the entry is missing from the runtime lombok jar), it throws Fail(\"api class %s cannot be found\"). It indicates a broken or incomplete lombok distribution.","triggerScenarios":"Running the PublicApiCreator (lombok's jar-creation tool) while the classpath lombok jar lacks one of the expected resource names in toCopy — getResourceAsStream(\"/\" + resourceName) returns null.","commonSituations":"Using a trimmed, repackaged, shaded, or corrupted lombok jar; IDE-bundled lombok copies that strip classes; mismatched lombok version where toCopy lists resources absent from that build.","solutions":["Run the tool against the official, complete lombok jar from Maven Central, not a shaded/trimmed copy.","Verify the resource actually exists in the jar (jar tf lombok.jar | grep <resourceName>).","Align the tool version and lombok jar version — an older/newer mix can list resources that don't exist.","Re-download the lombok jar; a corrupted download can drop entries.","If building lombok from source, run the full build so all API classes are produced before creating the API jar."],"exampleFix":"// before\njava -cp my-shaded-lombok.jar lombok.core.PublicApiCreatorApp out.jar\n// after\njava -cp org.projectlombok-lombok-1.18.30.jar lombok.core.PublicApiCreatorApp out.jar","handlingStrategy":"try-catch","validationCode":"String res = \"/\" + resourceName; if (Lombok.class.getResource(res) == null) throw new IllegalStateException(\"Missing resource in lombok jar: \" + resourceName);","typeGuard":"function resourceExists(name) { return PublicApiCreatorApp.class.getResource(\"/\" + name) != null; }","tryCatchPattern":"try { writeApiJar(out, toCopy); } catch (Fail f) { log.error(\"Incomplete lombok jar: \" + f.getMessage() + \" — use the official unshaded jar\"); }","preventionTips":["Run the API creator only against the official lombok jar.","Verify with `jar tf lombok.jar` that all expected entries exist.","Never shade/trim lombok before running this tool.","Keep tool and jar versions aligned."],"tags":["lombok","jar","resource-not-found","build-tooling"],"backgroundTag":"resource-not-found","analyzedSha":"6d6a3e9fec0a9555702561fbeb8eac836575116e","analyzedAt":"2026-09-07T23:18:01.841Z","contentChangedAt":"2026-09-07T23:18:01.841Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}