{"record":{"id":"5a668aa23de82a95","repo":"projectlombok/lombok","slug":"can-t-translate-guess-to-a-class-object","errorCode":null,"errorMessage":"Can't translate ${guess} to a class object.","messagePattern":"Can't translate (.+?) to a class object\\.","errorType":"exception","errorClass":"AnnotationValueDecodeFail","httpStatus":null,"severity":"error","filePath":"src/core/lombok/core/AnnotationValues.java","lineNumber":357,"sourceCode":"\t\t\n\t\tif (Enum.class.isAssignableFrom(expected) ) {\n\t\t\tif (guess instanceof FieldSelect) {\n\t\t\t\tString fieldSel = ((FieldSelect) guess).getFinalPart();\n\t\t\t\tfor (Object enumConstant : expected.getEnumConstants()) {\n\t\t\t\t\tString target = ((Enum<?>) enumConstant).name();\n\t\t\t\t\tif (target.equals(fieldSel)) return enumConstant;\n\t\t\t\t}\n\t\t\t\tthrow new AnnotationValueDecodeFail(v,\n\t\t\t\t\t\"Can't translate \" + fieldSel + \" to an enum of type \" + expected, pos);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (expected == Class.class) {\n\t\t\tif (guess instanceof ClassLiteral) try {\n\t\t\t\tString classLit = ((ClassLiteral) guess).getClassName();\n\t\t\t\treturn Class.forName(toFQ(classLit));\n\t\t\t} catch (ClassNotFoundException e) {\n\t\t\t\tthrow new AnnotationValueDecodeFail(v,\n\t\t\t\t\t\"Can't translate \" + guess + \" to a class object.\", pos);\n\t\t\t}\n\t\t}\n\t\t\n\t\tif (guess instanceof AnnotationValues) {\n\t\t\treturn ((AnnotationValues<?>) guess).getInstance();\n\t\t}\n\t\t\n\t\tif (guess instanceof FieldSelect) throw new AnnotationValueDecodeFail(v,\n\t\t\t\"You must use constant literals in lombok annotations; they cannot be references to (static) fields.\", pos);\n\t\t\n\t\tthrow new AnnotationValueDecodeFail(v,\n\t\t\t\"Can't translate a \" + guess.getClass() + \" to the expected \" + expected, pos);\n\t}\n\t\n\t/**\n\t * Returns the raw expressions used for the provided {@code annotationMethodName}.\n\t * ","sourceCodeStart":339,"sourceCodeEnd":375,"githubUrl":"https://github.com/projectlombok/lombok/blob/6d6a3e9fec0a9555702561fbeb8eac836575116e/src/core/lombok/core/AnnotationValues.java#L339-L375","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n@Builder(obvious = true) referencing MyClassyHelper.class // typo\n// after\n@X(helper = com.example.MyClassyHelper.class) // correct FQN, class on classpath","handlingStrategy":"validation","validationCode":"try { Class.forName(fqn); } catch (ClassNotFoundException e) { throw new IllegalStateException(\"Class in annotation not on classpath: \" + fqn); }","typeGuard":"function classExists(fqn) { try { java.lang.Class.forName(fqn); return true; } catch (ClassNotFoundException e) { return false; } }","tryCatchPattern":"try { Class<?> c = annotationValues.getValue(\"target\"); } catch (AnnotationValueDecodeFail e) { log.error(\"Class literal in annotation could not be loaded: \" + e.getMessage()); }","preventionTips":["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."],"tags":["annotations","lombok","class-not-found","classpath"],"backgroundTag":"class-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"}