{"record":{"id":"eb79da58cfa0df0b","repo":"projectlombok/lombok","slug":"can-t-translate-a-guess-getclass-to-the-expec","errorCode":null,"errorMessage":"Can't translate a ${guess.getClass()} to the expected ${expected}","messagePattern":"Can't translate a (.+?) to the expected (.+?)","errorType":"exception","errorClass":"AnnotationValueDecodeFail","httpStatus":null,"severity":"error","filePath":"src/core/lombok/core/AnnotationValues.java","lineNumber":369,"sourceCode":"\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 * \n\t * You should use this method for annotation methods that return {@code Class} objects. Remember that\n\t * class literals end in \".class\" which you probably want to strip off.\n\t */\n\tpublic List<String> getRawExpressions(String annotationMethodName) {\n\t\tAnnotationValue v = values.get(annotationMethodName);\n\t\treturn v == null ? Collections.<String>emptyList() : v.raws;\n\t}\n\t\n\t/**\n\t * Returns the actual expressions used for the provided {@code annotationMethodName}.\n\t */\n\tpublic List<Object> getActualExpressions(String annotationMethodName) {","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/projectlombok/lombok/blob/6d6a3e9fec0a9555702561fbeb8eac836575116e/src/core/lombok/core/AnnotationValues.java#L351-L387","documentation":"This is guessToType()'s catch-all: when a guess (the compiler's parsed representation of an annotation value) is of a node type lombok has no converter for — not a literal, FieldSelect, ClassLiteral, or nested AnnotationValues — it throws AnnotationValueDecodeFail reporting the guess's class and the expected type. It signals an unsupported/unexpected annotation value shape.","triggerScenarios":"An annotation member receives a parsed expression whose AST node class does not match any branch in guessToType (e.g. complex expressions, binary operations, or compiler-specific nodes) — the final unconditional throw in guessToType.","commonSituations":"Writing expressions like 1 + 2 or string concatenation in annotation values; compiler/IDE-specific AST variants after a JDK or Eclipse version change; custom AST node types from other annotation processors interleaving with lombok.","solutions":["Simplify the annotation value to a plain literal (string, number, boolean, enum constant, or class literal).","Remove any computed expressions from the annotation — Java requires constant expressions, lombok requires simple literals.","Reproduce with a minimal annotation usage; if it persists on a valid literal, report a lombok bug with compiler version.","Check JDK/Eclipse compatibility of your lombok version; upgrade lombok to match your compiler."],"exampleFix":"// before\n@MyAnn(count = 1 + 1) // expression node unsupported\n// after\n@MyAnn(count = 2)","handlingStrategy":"validation","validationCode":"Set<String> allowed = Set.of(\"literal\", \"fieldSelect\", \"classLiteral\", \"annotation\"); if (!allowed.contains(guessKind)) throw new IllegalArgumentException(\"Unsupported annotation value shape: \" + guessKind);","typeGuard":"function isSupportedAnnotationValue(expr) { return /^(\"[^\"]*\"|'[^']*'|\\d+|\\d+\\.\\d+|true|false|[A-Z][\\w$]*|[A-Za-z_$][\\w$.]*\\.class|\\[[^\\]]*\\])$/.test(expr.trim()); }","tryCatchPattern":"try { V v = annotationValues.getValue(\"member\"); } catch (AnnotationValueDecodeFail e) { log.error(\"Unsupported annotation value shape; use a plain literal\"); }","preventionTips":["Keep annotation values to simple compile-time literals.","Avoid expressions and exotic AST shapes in annotation arguments.","Pin a lombok version compatible with your JDK/IDE and upgrade together."],"tags":["annotations","lombok","ast","unsupported-value"],"backgroundTag":"type-mismatch","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"}