projectlombok/lombok · error · Fail

api class cannot be found

Error message

api class %s cannot be found

What it means

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.

Solutions

  1. Run the tool against the official, complete lombok jar from Maven Central, not a shaded/trimmed copy.
  2. Verify the resource actually exists in the jar (jar tf lombok.jar | grep <resourceName>).
  3. Align the tool version and lombok jar version — an older/newer mix can list resources that don't exist.
  4. Re-download the lombok jar; a corrupted download can drop entries.
  5. If building lombok from source, run the full build so all API classes are produced before creating the API jar.

Example fix

// before
java -cp my-shaded-lombok.jar lombok.core.PublicApiCreatorApp out.jar
// after
java -cp org.projectlombok-lombok-1.18.30.jar lombok.core.PublicApiCreatorApp out.jar
Defensive patterns

Strategy: try-catch

Validate before calling

String res = "/" + resourceName; if (Lombok.class.getResource(res) == null) throw new IllegalStateException("Missing resource in lombok jar: " + resourceName);

Type guard

function resourceExists(name) { return PublicApiCreatorApp.class.getResource("/" + name) != null; }

Try / catch

try { writeApiJar(out, toCopy); } catch (Fail f) { log.error("Incomplete lombok jar: " + f.getMessage() + " — use the official unshaded jar"); }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of projectlombok/lombok@6d6a3e9fec (2026-09-07). Data as JSON: /api/errors/c9c4b1ba6c05de52. Report an issue: GitHub.

Appendix: source

Thrown at src/core/lombok/core/PublicApiCreatorApp.java:132

			}
		} finally {
			self.close();
		}
		
		if (toCopy.isEmpty()) {
			System.out.println("Not generating lombok-api.jar: No lombok api classes required!");
			return 1;
		}
		
		OutputStream out = new FileOutputStream(outFile);
		boolean success = false;
		try {
			JarOutputStream jar = new JarOutputStream(out);
			for (String resourceName : toCopy) {
				InputStream in = Lombok.class.getResourceAsStream("/" + resourceName);
				try {
					if (in == null) {
						throw new Fail(String.format("api class %s cannot be found", resourceName));
					}
					writeIntoJar(jar, resourceName, in);
				} finally {
					if (in != null) in.close();
				}
			}
			jar.close();
			out.close();
			
			System.out.println("Successfully created: " + canonical(outFile));
			
			return 0;
		} catch (Throwable t) {
			try { out.close();} catch (Throwable ignore) {}
			if (!success) outFile.delete();
			if (t instanceof Fail) {
				System.err.println(t.getMessage());
				return 1;

View on GitHub (pinned to 6d6a3e9fec)