projectlombok/lombok · error · AnnotationValueDecodeFail

Can't translate to an enum of type

Error message

Can't translate ${fieldSel} to an enum of type ${expected}

What it means

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.

Solutions

  1. Correct the enum constant name in the annotation to one that exists in the target enum type.
  2. Check you are referencing the intended enum class (not a same-named different enum).
  3. If a library upgraded and removed/renamed the constant, migrate to the new name per its changelog.
  4. Use the IDE's code completion on the annotation member to pick a valid constant.

Example fix

// before
@Accessors(prefix = "_") // if a custom enum member: @Mode(FASET) but enum has FAST only
// after
@Mode(FAST) // constant name matching an actual enum constant
Defensive patterns

Strategy: validation

Validate before calling

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());

Type guard

ExpectedEnum e = java.util.Arrays.stream(ExpectedEnum.values()).filter(c -> c.name().equals(name)).findFirst().orElse(null); // null => would fail

Try / catch

try { V v = annotationValues.getValue("level"); } catch (AnnotationValueDecodeFail e) { log.error("Unknown enum constant in annotation: " + e.getMessage()); }

Prevention

When it happens

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

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

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at src/core/lombok/core/AnnotationValues.java:347

			if (guess instanceof Boolean) return ((Boolean) guess).booleanValue();
		}
		
		if (expected == char.class || expected == Character.class) {
			if (guess instanceof Character) return ((Character) guess).charValue();
		}
		
		if (expected == String.class) {
			if (guess instanceof String) return guess;
		}
		
		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();
		}
		

View on GitHub (pinned to 6d6a3e9fec)