{"record":{"id":"ddf78ca513b0856b","repo":"projectlombok/lombok","slug":"can-t-translate-fieldsel-to-an-enum-of-type-e","errorCode":null,"errorMessage":"Can't translate ${fieldSel} to an enum of type ${expected}","messagePattern":"Can't translate (.+?) to an enum of type (.+?)","errorType":"exception","errorClass":"AnnotationValueDecodeFail","httpStatus":null,"severity":"error","filePath":"src/core/lombok/core/AnnotationValues.java","lineNumber":347,"sourceCode":"\t\t\tif (guess instanceof Boolean) return ((Boolean) guess).booleanValue();\n\t\t}\n\t\t\n\t\tif (expected == char.class || expected == Character.class) {\n\t\t\tif (guess instanceof Character) return ((Character) guess).charValue();\n\t\t}\n\t\t\n\t\tif (expected == String.class) {\n\t\t\tif (guess instanceof String) return guess;\n\t\t}\n\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","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/projectlombok/lombok/blob/6d6a3e9fec0a9555702561fbeb8eac836575116e/src/core/lombok/core/AnnotationValues.java#L329-L365","documentation":"guessToType() resolves FieldSelect guesses to enum constants by matching the selected name against expected.getEnumConstants(). When no enum constant name equals the FieldSelect's final part, lombok throws AnnotationValueDecodeFail saying the field selection cannot be translated to that enum type. In practice: an annotation member of enum type was given a name that does not exist in the enum.","triggerScenarios":"An annotation value like @MyAnn(level = Level.WARN) where Level has no constant named WARN, or a FieldSelect guess resolves to a name not among the target enum's constants.","commonSituations":"Enum renamed or constant removed after a library upgrade while annotation source still references the old name; typo in the constant; importing the wrong enum class with same simple name.","solutions":["Correct the enum constant name in the annotation to one that exists in the target enum type.","Check you are referencing the intended enum class (not a same-named different enum).","If a library upgraded and removed/renamed the constant, migrate to the new name per its changelog.","Use the IDE's code completion on the annotation member to pick a valid constant."],"exampleFix":"// before\n@Accessors(prefix = \"_\") // if a custom enum member: @Mode(FASET) but enum has FAST only\n// after\n@Mode(FAST) // constant name matching an actual enum constant","handlingStrategy":"validation","validationCode":"boolean valid = java.util.Arrays.stream(ExpectedEnum.values()).anyMatch(c -> c.name().equals(constantName)); if (!valid) throw new IllegalArgumentException(constantName + \" is not a constant of \" + ExpectedEnum.class.getName());","typeGuard":"ExpectedEnum e = java.util.Arrays.stream(ExpectedEnum.values()).filter(c -> c.name().equals(name)).findFirst().orElse(null); // null => would fail","tryCatchPattern":"try { V v = annotationValues.getValue(\"level\"); } catch (AnnotationValueDecodeFail e) { log.error(\"Unknown enum constant in annotation: \" + e.getMessage()); }","preventionTips":["Use IDE completion for enum members in annotations.","After upgrading a library, grep annotation usages for renamed/removed enum constants.","Qualify the exact enum type to avoid same-named enum collisions."],"tags":["annotations","lombok","enum","compile-time"],"backgroundTag":"invalid-enum-value","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"}