From 40232f4e22e19ed590f44852b121ba78b959b87e Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Apr 2017 18:05:30 +0200 Subject: [PATCH] ASM annotation visitor defensively accesses enum constants Issue: SPR-15442 (cherry picked from commit 4838f06) --- .../AbstractRecursiveAnnotationVisitor.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/AbstractRecursiveAnnotationVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/AbstractRecursiveAnnotationVisitor.java index bd42e059d34..11341eac2d4 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/AbstractRecursiveAnnotationVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/AbstractRecursiveAnnotationVisitor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ package org.springframework.core.type.classreading; import java.lang.reflect.Field; +import java.security.AccessControlException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -80,14 +81,21 @@ abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor { Class enumType = this.classLoader.loadClass(Type.getType(asmTypeDescriptor).getClassName()); Field enumConstant = ReflectionUtils.findField(enumType, attributeValue); if (enumConstant != null) { + ReflectionUtils.makeAccessible(enumConstant); valueToUse = enumConstant.get(null); } } catch (ClassNotFoundException ex) { logger.debug("Failed to classload enum type while reading annotation metadata", ex); } + catch (NoClassDefFoundError ex) { + logger.debug("Failed to classload enum type while reading annotation metadata", ex); + } catch (IllegalAccessException ex) { - logger.warn("Could not access enum value while reading annotation metadata", ex); + logger.debug("Could not access enum value while reading annotation metadata", ex); + } + catch (AccessControlException ex) { + logger.debug("Could not access enum value while reading annotation metadata", ex); } return valueToUse; }