Fix ArrayStoreException reading subclassed enums

Fix ASM AnnotationAttributesReadingVisitor to correctly deal with
subclasses enums.

Issue: SPR-10914
This commit is contained in:
Phillip Webb
2013-09-24 17:19:29 -07:00
parent f3611e767e
commit 8abe949734
2 changed files with 23 additions and 3 deletions

View File

@@ -28,7 +28,6 @@ import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.asm.AnnotationVisitor;
import org.springframework.asm.SpringAsmInfo;
import org.springframework.asm.Type;
@@ -131,7 +130,13 @@ final class RecursiveAnnotationArrayVisitor extends AbstractRecursiveAnnotationV
newValue = ObjectUtils.addObjectToArray((Object[]) existingValue, newValue);
}
else {
Object[] newArray = (Object[]) Array.newInstance(newValue.getClass(), 1);
Class<?> arrayClass = newValue.getClass();
if(Enum.class.isAssignableFrom(arrayClass)) {
while(arrayClass.getSuperclass() != null && !arrayClass.isEnum()) {
arrayClass = arrayClass.getSuperclass();
}
}
Object[] newArray = (Object[]) Array.newInstance(arrayClass, 1);
newArray[0] = newValue;
newValue = newArray;
}