projectlombok/lombok · error · AnnotationValueDecodeFail
Can't translate to a class object.
Error message
Can't translate ${guess} to a class object. What it means
guessToType() handles Class-typed annotation members by resolving ClassLiteral guesses via Class.forName(toFQ(...)). If the class literal's name cannot be loaded (ClassNotFoundException), lombok throws AnnotationValueDecodeFail: the annotation references a class that could not be resolved to a class object at annotation-processing time.
Solutions
- Fix the class name/package in the class literal so it resolves at compile time.
- Add the missing dependency/jar to the compile (and annotation-processing) classpath.
- Verify the class still exists — check for renames after dependency upgrades.
- Use a fully qualified class literal instead of relying on imports/wildcards.
Example fix
// before @Builder(obvious = true) referencing MyClassyHelper.class // typo // after @X(helper = com.example.MyClassyHelper.class) // correct FQN, class on classpath
Defensive patterns
Strategy: validation
Validate before calling
try { Class.forName(fqn); } catch (ClassNotFoundException e) { throw new IllegalStateException("Class in annotation not on classpath: " + fqn); } Type guard
function classExists(fqn) { try { java.lang.Class.forName(fqn); return true; } catch (ClassNotFoundException e) { return false; } } Try / catch
try { Class<?> c = annotationValues.getValue("target"); } catch (AnnotationValueDecodeFail e) { log.error("Class literal in annotation could not be loaded: " + e.getMessage()); } Prevention
- Fully qualify class literals and confirm the dependency is on the compile classpath.
- After dependency upgrades, verify referenced classes still exist.
- Avoid provided/runtime-only classes inside annotation values used by processors.
When it happens
Trigger: An annotation member of type Class (e.g. Class<?> value()) given a class literal whose toFQ-qualified name is not found on the compile classpath — ClassNotFoundException thrown from Class.forName inside guessToType.
Common situations: Misspelled or wrongly packaged class in an annotation like @Delegate(types = {...}); dependency missing from the annotation processor's classpath; class exists only at runtime (provided scope differences) or was removed in a dependency upgrade.
Related errors
- I can't make sense of this annotation value. Try using a…
- Expected a single value, but
- Can't translate to an enum of type
- You must use constant literals in lombok annotations; they…
- Can't translate a to the expected
AI-assisted analysis of projectlombok/lombok@6d6a3e9fec (2026-09-07).
Data as JSON: /api/errors/5a668aa23de82a95.
Report an issue: GitHub.
Appendix: source
Thrown at src/core/lombok/core/AnnotationValues.java:357
if (Enum.class.isAssignableFrom(expected) ) {
if (guess instanceof FieldSelect) {
String fieldSel = ((FieldSelect) guess).getFinalPart();
for (Object enumConstant : expected.getEnumConstants()) {
String target = ((Enum<?>) enumConstant).name();
if (target.equals(fieldSel)) return enumConstant;
}
throw new AnnotationValueDecodeFail(v,
"Can't translate " + fieldSel + " to an enum of type " + expected, pos);
}
}
if (expected == Class.class) {
if (guess instanceof ClassLiteral) try {
String classLit = ((ClassLiteral) guess).getClassName();
return Class.forName(toFQ(classLit));
} catch (ClassNotFoundException e) {
throw new AnnotationValueDecodeFail(v,
"Can't translate " + guess + " to a class object.", pos);
}
}
if (guess instanceof AnnotationValues) {
return ((AnnotationValues<?>) guess).getInstance();
}
if (guess instanceof FieldSelect) throw new AnnotationValueDecodeFail(v,
"You must use constant literals in lombok annotations; they cannot be references to (static) fields.", pos);
throw new AnnotationValueDecodeFail(v,
"Can't translate a " + guess.getClass() + " to the expected " + expected, pos);
}
/**
* Returns the raw expressions used for the provided {@code annotationMethodName}.
* View on GitHub (pinned to 6d6a3e9fec)