jdk/src/share/classes/javax/management/openmbean/OpenMBeanAttributeInfoSupport.java
changeset 18220 1d724730bd2c
parent 5506 202f599c92aa
child 21656 d4c777ccb1db
equal deleted inserted replaced
18219:d4cd832b9802 18220:1d724730bd2c
    43 import javax.management.Descriptor;
    43 import javax.management.Descriptor;
    44 import javax.management.DescriptorRead;
    44 import javax.management.DescriptorRead;
    45 import javax.management.ImmutableDescriptor;
    45 import javax.management.ImmutableDescriptor;
    46 import javax.management.MBeanAttributeInfo;
    46 import javax.management.MBeanAttributeInfo;
    47 import com.sun.jmx.remote.util.EnvHelp;
    47 import com.sun.jmx.remote.util.EnvHelp;
       
    48 import sun.reflect.misc.ConstructorUtil;
       
    49 import sun.reflect.misc.MethodUtil;
       
    50 import sun.reflect.misc.ReflectUtil;
    48 
    51 
    49 /**
    52 /**
    50  * Describes an attribute of an open MBean.
    53  * Describes an attribute of an open MBean.
    51  *
    54  *
    52  *
    55  *
   688     }
   691     }
   689 
   692 
   690     private static <T> T convertFromString(String s, OpenType<T> openType) {
   693     private static <T> T convertFromString(String s, OpenType<T> openType) {
   691         Class<T> c;
   694         Class<T> c;
   692         try {
   695         try {
       
   696             ReflectUtil.checkPackageAccess(openType.safeGetClassName());
   693             c = cast(Class.forName(openType.safeGetClassName()));
   697             c = cast(Class.forName(openType.safeGetClassName()));
   694         } catch (ClassNotFoundException e) {
   698         } catch (ClassNotFoundException e) {
   695             throw new NoClassDefFoundError(e.toString());  // can't happen
   699             throw new NoClassDefFoundError(e.toString());  // can't happen
   696         }
   700         }
   697 
   701 
   698         // Look for: public static T valueOf(String)
   702         // Look for: public static T valueOf(String)
   699         Method valueOf;
   703         Method valueOf;
   700         try {
   704         try {
       
   705             // It is safe to call this plain Class.getMethod because the class "c"
       
   706             // was checked before by ReflectUtil.checkPackageAccess(openType.safeGetClassName());
   701             valueOf = c.getMethod("valueOf", String.class);
   707             valueOf = c.getMethod("valueOf", String.class);
   702             if (!Modifier.isStatic(valueOf.getModifiers()) ||
   708             if (!Modifier.isStatic(valueOf.getModifiers()) ||
   703                     valueOf.getReturnType() != c)
   709                     valueOf.getReturnType() != c)
   704                 valueOf = null;
   710                 valueOf = null;
   705         } catch (NoSuchMethodException e) {
   711         } catch (NoSuchMethodException e) {
   706             valueOf = null;
   712             valueOf = null;
   707         }
   713         }
   708         if (valueOf != null) {
   714         if (valueOf != null) {
   709             try {
   715             try {
   710                 return c.cast(valueOf.invoke(null, s));
   716                 return c.cast(MethodUtil.invoke(valueOf, null, new Object[] {s}));
   711             } catch (Exception e) {
   717             } catch (Exception e) {
   712                 final String msg =
   718                 final String msg =
   713                     "Could not convert \"" + s + "\" using method: " + valueOf;
   719                     "Could not convert \"" + s + "\" using method: " + valueOf;
   714                 throw new IllegalArgumentException(msg, e);
   720                 throw new IllegalArgumentException(msg, e);
   715             }
   721             }
   716         }
   722         }
   717 
   723 
   718         // Look for: public T(String)
   724         // Look for: public T(String)
   719         Constructor<T> con;
   725         Constructor<T> con;
   720         try {
   726         try {
       
   727             // It is safe to call this plain Class.getConstructor because the class "c"
       
   728             // was checked before by ReflectUtil.checkPackageAccess(openType.safeGetClassName());
   721             con = c.getConstructor(String.class);
   729             con = c.getConstructor(String.class);
   722         } catch (NoSuchMethodException e) {
   730         } catch (NoSuchMethodException e) {
   723             con = null;
   731             con = null;
   724         }
   732         }
   725         if (con != null) {
   733         if (con != null) {