diff --git a/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java b/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
index 146d7fc5762..7142c803bb9 100644
--- a/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
+++ b/core/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
@@ -19,28 +19,18 @@
package org.apache.cxf.common.util;
-import java.beans.BeanInfo;
-import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.cxf.common.classloader.ClassLoaderUtils;
public final class ReflectionUtil {
- private static Method springBeanUtilsDescriptorFetcher;
- private static boolean springChecked;
-
private ReflectionUtil() {
// intentionally empty
}
@@ -195,61 +185,6 @@ public T run() {
});
}
- /**
- * create own array of property descriptors to:
- *
- * - prevent memory leaks by Introspector's cache
- * - get correct type for generic properties from superclass
- * that are limited to a specific type in beanClass
- * see http://bugs.sun.com/view_bug.do?bug_id=6528714
- * we cannot use BeanUtils.getPropertyDescriptors because of issue SPR-6063
- *
- * @param refClass calling class for class loading.
- * @param beanInfo Bean in question
- * @param beanClass class for bean in question
- * @param propertyDescriptors raw descriptors
- */
- public static PropertyDescriptor[] getPropertyDescriptorsAvoidSunBug(Class> refClass,
- BeanInfo beanInfo,
- Class> beanClass,
- PropertyDescriptor[] propertyDescriptors) {
- if (!springChecked) {
- try {
- springChecked = true;
- Class> cls = ClassLoaderUtils
- .loadClass("org.springframework.beans.BeanUtils", refClass);
- springBeanUtilsDescriptorFetcher
- = cls.getMethod("getPropertyDescriptor", Class.class, String.class);
- } catch (Exception e) {
- //ignore - just assume it's an unsupported/unknown annotation
- }
- }
-
- if (springBeanUtilsDescriptorFetcher != null) {
- if (propertyDescriptors != null) {
- List descriptors = new ArrayList<>(propertyDescriptors.length);
- for (int i = 0; i < propertyDescriptors.length; i++) {
- PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
- try {
- propertyDescriptor = (PropertyDescriptor)springBeanUtilsDescriptorFetcher.invoke(null,
- beanClass,
- propertyDescriptor.getName());
- if (propertyDescriptor != null) {
- descriptors.add(propertyDescriptor);
- }
- } catch (IllegalArgumentException | IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e.getCause());
- }
- }
- return descriptors.toArray(new PropertyDescriptor[0]);
- }
- return null;
- }
- return beanInfo.getPropertyDescriptors();
- }
-
/**
* Look for a specified annotation on a method. If there, return it. If not, search it's containing class.
* Assume that the annotation is marked @Inherited.
diff --git a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
index aa4fef6c344..6e702d0e9de 100644
--- a/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
+++ b/rt/databinding/aegis/src/main/java/org/apache/cxf/aegis/type/basic/BeanTypeInfo.java
@@ -22,6 +22,8 @@
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -38,9 +40,12 @@
import org.apache.cxf.aegis.type.AegisType;
import org.apache.cxf.aegis.type.TypeCreator;
import org.apache.cxf.aegis.type.TypeMapping;
-import org.apache.cxf.common.util.ReflectionUtil;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
public class BeanTypeInfo {
+ private static Method springBeanUtilsDescriptorFetcher;
+ private static boolean springChecked;
+
private Map mappedName2typeName = new HashMap<>();
private Map mappedName2pdName = new HashMap<>();
private Map mappedName2type = new HashMap<>();
@@ -106,6 +111,61 @@ public void initialize() {
}
}
+ /**
+ * create own array of property descriptors to:
+ *
+ * - prevent memory leaks by Introspector's cache
+ * - get correct type for generic properties from superclass
+ * that are limited to a specific type in beanClass
+ * see http://bugs.sun.com/view_bug.do?bug_id=6528714
+ * we cannot use BeanUtils.getPropertyDescriptors because of issue SPR-6063
+ *
+ * @param refClass calling class for class loading.
+ * @param beanInfo Bean in question
+ * @param beanClass class for bean in question
+ * @param propertyDescriptors raw descriptors
+ */
+ public static PropertyDescriptor[] getPropertyDescriptorsAvoidSunBug(Class> refClass,
+ BeanInfo beanInfo,
+ Class> beanClass,
+ PropertyDescriptor[] propertyDescriptors) {
+ if (!springChecked) {
+ try {
+ springChecked = true;
+ Class> cls = ClassLoaderUtils
+ .loadClass("org.springframework.beans.BeanUtils", refClass);
+ springBeanUtilsDescriptorFetcher
+ = cls.getMethod("getPropertyDescriptor", Class.class, String.class);
+ } catch (Exception e) {
+ //ignore - just assume it's an unsupported/unknown annotation
+ }
+ }
+
+ if (springBeanUtilsDescriptorFetcher != null) {
+ if (propertyDescriptors != null) {
+ List descriptors = new ArrayList<>(propertyDescriptors.length);
+ for (int i = 0; i < propertyDescriptors.length; i++) {
+ PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
+ try {
+ propertyDescriptor = (PropertyDescriptor)springBeanUtilsDescriptorFetcher.invoke(null,
+ beanClass,
+ propertyDescriptor.getName());
+ if (propertyDescriptor != null) {
+ descriptors.add(propertyDescriptor);
+ }
+ } catch (IllegalArgumentException | IllegalAccessException e) {
+ throw new RuntimeException(e);
+ } catch (InvocationTargetException e) {
+ throw new RuntimeException(e.getCause());
+ }
+ }
+ return descriptors.toArray(new PropertyDescriptor[0]);
+ }
+ return null;
+ }
+ return beanInfo.getPropertyDescriptors();
+ }
+
private synchronized void initializeSync() {
if (!initialized) {
for (int i = 0; i < descriptors.length; i++) {
@@ -285,10 +345,10 @@ private void initializeProperties() {
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
if (propertyDescriptors != null) {
// see comments on this function.
- descriptors = ReflectionUtil.getPropertyDescriptorsAvoidSunBug(getClass(),
- beanInfo,
- beanClass,
- propertyDescriptors);
+ descriptors = getPropertyDescriptorsAvoidSunBug(getClass(),
+ beanInfo,
+ beanClass,
+ propertyDescriptors);
}
}