procyon icon indicating copy to clipboard operation
procyon copied to clipboard

Incorrect Enum handling in CodeGenerator

Open BladeWise opened this issue 3 years ago • 0 comments

The CodeGenerator tries to identify an Enum field using toString. This can fail if the toString method of the field has been customized (e.g. ChronoUnit).

I suppose that the following code https://github.com/mstrobel/procyon/blob/88a95fa93c58322393174f84543edc7a0a2ca44d/Procyon.Reflection/src/main/java/com/strobel/reflection/emit/CodeGenerator.java#L1505-L1507 should be changed to

if (unboxedType.isEnum()) {
	getField(unboxedType.getField(((Enum<?>)value).name()));
	return true;
}

considering that name() is the value expected by Enum.valueOf too.

BladeWise avatar Feb 22 '22 13:02 BladeWise