106. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 9/25/2018 2:13:02 PM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

106.1 Files compared

# Location File Last Modified
1 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\mbeanserver Introspector.java Mon Jan 22 14:46:50 2018 UTC
2 build 3.zip\build 3\MHLTH_YS_137_Source\JavaScript\resources\javaJDF-1.8.0\src\com\sun\jmx\mbeanserver Introspector.java Wed Sep 12 16:25:56 2018 UTC

106.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 1630
Changed 1 2
Inserted 0 0
Removed 0 0

106.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

106.4 Active regular expressions

No regular expressions were active.

106.5 Comparison detail

  1   /*
  2    * Copyrig ht (c) 199 9, 2013, O racle and/ or its aff iliates. A ll rights  reserved.
  3    * DO NOT  ALTER OR R EMOVE COPY RIGHT NOTI CES OR THI S FILE HEA DER.
  4    *
  5    * This co de is free  software;  you can r edistribut e it and/o r modify i t
  6    * under t he terms o f the GNU  General Pu blic Licen se version  2 only, a s
  7    * publish ed by the  Free Softw are Founda tion.  Ora cle design ates this
  8    * particu lar file a s subject  to the "Cl asspath" e xception a s provided
  9    * by Orac le in the  LICENSE fi le that ac companied  this code.
  10    *
  11    * This co de is dist ributed in  the hope  that it wi ll be usef ul, but WI THOUT
  12    * ANY WAR RANTY; wit hout even  the implie d warranty  of MERCHA NTABILITY  or
  13    * FITNESS  FOR A PAR TICULAR PU RPOSE.  Se e the GNU  General Pu blic Licen se
  14    * version  2 for mor e details  (a copy is  included  in the LIC ENSE file  that
  15    * accompa nied this  code).
  16    *
  17    * You sho uld have r eceived a  copy of th e GNU Gene ral Public  License v ersion
  18    * 2 along  with this  work; if  not, write  to the Fr ee Softwar e Foundati on,
  19    * Inc., 5 1 Franklin  St, Fifth  Floor, Bo ston, MA 0 2110-1301  USA.
  20    *
  21    * Please  contact Or acle, 500  Oracle Par kway, Redw ood Shores , CA 94065  USA
  22    * or visi t www.orac le.com if  you need a dditional  informatio n or have  any
  23    * questio ns.
  24    */
  25  
  26   package co m.sun.jmx. mbeanserve r;
  27  
  28   import jav a.lang.ann otation.An notation;
  29   import jav a.lang.ref .SoftRefer ence;
  30   import jav a.lang.ref lect.Annot atedElemen t;
  31   import jav a.lang.ref lect.Const ructor;
  32   import jav a.lang.ref lect.Metho d;
  33   import jav a.lang.ref lect.Modif ier;
  34   import jav a.lang.ref lect.Proxy ;
  35   import jav a.lang.ref lect.Undec laredThrow ableExcept ion;
  36   import jav a.util.Arr ays;
  37   import jav a.util.Col lections;
  38   import jav a.util.Has hMap;
  39   import jav a.util.Lis t;
  40   import jav a.util.Lin kedList;
  41   import jav a.util.Loc ale;
  42   import jav a.util.Map ;
  43   import jav a.util.Wea kHashMap;
  44  
  45   import jav ax.managem ent.Descri ptor;
  46   import jav ax.managem ent.Descri ptorKey;
  47   import jav ax.managem ent.Dynami cMBean;
  48   import jav ax.managem ent.Immuta bleDescrip tor;
  49   import jav ax.managem ent.MBeanI nfo;
  50   import jav ax.managem ent.NotCom pliantMBea nException ;
  51  
  52   import com .sun.jmx.r emote.util .EnvHelp;
  53   import jav a.lang.ref lect.Array ;
  54   import jav a.lang.ref lect.Invoc ationTarge tException ;
  55   import jav a.security .AccessCon troller;
  56   import jav ax.managem ent.Attrib uteNotFoun dException ;
  57   import jav ax.managem ent.openmb ean.Compos iteData;
  58   import sun .reflect.m isc.Method Util;
  59   import sun .reflect.m isc.Reflec tUtil;
  60  
  61   /**
  62    * This cl ass contai ns the met hods for p erforming  all the te sts needed  to verify
  63    * that a  class repr esents a J MX complia nt MBean.
  64    *
  65    * @since  1.5
  66    */
  67   public cla ss Introsp ector {
  68       final  public sta tic boolea n ALLOW_NO NPUBLIC_MB EAN;
  69       static  {
  70           St ring val =  AccessCon troller.do Privileged (new GetPr opertyActi on("jdk.jm x.mbeans.a llowNonPub lic"));
  71           AL LOW_NONPUB LIC_MBEAN  = Boolean. parseBoole an(val);
  72       }
  73  
  74        /*
  75        * --- ---------- ---------- ---------- ---------
  76        *  PR IVATE CONS TRUCTORS
  77        * --- ---------- ---------- ---------- ---------
  78        */
  79  
  80       // pri vate const ructor def ined to "h ide" the d efault pub lic constr uctor
  81       privat e Introspe ctor() {
  82  
  83           //  --------- ---------- ---------- -
  84           //  --------- ---------- ---------- -
  85  
  86       }
  87  
  88       /*
  89        * --- ---------- ---------- ---------- ---------
  90        *  PU BLIC METHO DS
  91        * --- ---------- ---------- ---------- ---------
  92        */
  93  
  94       /**
  95        * Tel l whether  a MBean of  the given  class is  a Dynamic  MBean.
  96        * Thi s method d oes nothin g more tha n returnin g
  97        * <pr e>
  98        * jav ax.managem ent.Dynami cMBean.cla ss.isAssig nableFrom( c)
  99        * </p re>
  100        * Thi s method d oes not ch eck for an y JMX MBea n complian ce:
  101        * <ul ><li>If <c ode>true</ code> is r eturned, t hen instan ces of
  102        *      <code>c</ code> are  DynamicMBe an.</li>
  103        *      <li>If <c ode>false< /code> is  returned,  then no fu rther
  104        *      assumptio n can be m ade on ins tances of  <code>c</c ode>.
  105        *      In partic ular, inst ances of < code>c</co de> may, o r may not
  106        *      be JMX st andard MBe ans.</li>
  107        * </u l>
  108        * @pa ram c The  class of t he MBean u nder exami nation.
  109        * @re turn <code >true</cod e> if inst ances of < code>c</co de> are
  110        *          Dynam ic MBeans,  <code>fal se</code>  otherwise.
  111        *
  112        **/
  113       public  static fi nal boolea n isDynami c(final Cl ass<?> c)  {
  114           //  Check if  the MBean  implements  the Dynam icMBean in terface
  115           re turn javax .managemen t.DynamicM Bean.class .isAssigna bleFrom(c) ;
  116       }
  117  
  118       /**
  119        * Bas ic method  for testin g that a M Bean of a  given clas s can be
  120        * ins tantiated  by the MBe an server. <p>
  121        * Thi s method c hecks that :
  122        * <ul ><li>The g iven class  is a conc rete class .</li>
  123        *      <li>The g iven class  exposes a t least on e public c onstructor .</li>
  124        * </u l>
  125        * If  these cond itions are  not met,  throws a N otComplian tMBeanExce ption.
  126        * @pa ram c The  class of t he MBean w e want to  create.
  127        * @ex ception No tCompliant MBeanExcep tion if th e MBean cl ass makes  it
  128        *             im possible t o instanti ate the MB ean from w ithin the
  129        *             MB eanServer.
  130        *
  131        **/
  132       public  static vo id testCre ation(Clas s<?> c)
  133           th rows NotCo mpliantMBe anExceptio n {
  134           //  Check if  the class  is a concr ete class
  135           fi nal int mo ds = c.get Modifiers( );
  136           if  (Modifier .isAbstrac t(mods) ||  Modifier. isInterfac e(mods)) {
  137                throw ne w NotCompl iantMBeanE xception(" MBean clas s must be  concrete") ;
  138           }
  139  
  140           //  Check if  the MBean  has a publ ic constru ctor
  141           fi nal Constr uctor<?>[]  consList  = c.getCon structors( );
  142           if  (consList .length ==  0) {
  143                throw ne w NotCompl iantMBeanE xception(" MBean clas s must hav e public c onstructor ");
  144           }
  145       }
  146  
  147       public  static vo id checkCo mpliance(C lass<?> mb eanClass)
  148       throws  NotCompli antMBeanEx ception {
  149           //  Is Dynami cMBean?
  150           //
  151           if  (DynamicM Bean.class .isAssigna bleFrom(mb eanClass))
  152                return;
  153           //  Is Standa rd MBean?
  154           //
  155           fi nal Except ion mbeanE xception;
  156           tr y {
  157                getStand ardMBeanIn terface(mb eanClass);
  158                return;
  159           }  catch (Not CompliantM BeanExcept ion e) {
  160                mbeanExc eption = e ;
  161           }
  162           //  Is MXBean ?
  163           //
  164           fi nal Except ion mxbean Exception;
  165           tr y {
  166                getMXBea nInterface (mbeanClas s);
  167                return;
  168           }  catch (Not CompliantM BeanExcept ion e) {
  169                mxbeanEx ception =  e;
  170           }
  171           fi nal String  msg =
  172                "MBean c lass " + m beanClass. getName()  + " does n ot impleme nt " +
  173                "Dynamic MBean, and  neither f ollows the  Standard  MBean conv entions ("  +
  174                mbeanExc eption.toS tring() +  ") nor the  MXBean co nventions  (" +
  175                mxbeanEx ception.to String() +  ")";
  176           th row new No tCompliant MBeanExcep tion(msg);
  177       }
  178  
  179       public  static <T > DynamicM Bean makeD ynamicMBea n(T mbean)
  180           th rows NotCo mpliantMBe anExceptio n {
  181           if  (mbean in stanceof D ynamicMBea n)
  182                return ( DynamicMBe an) mbean;
  183           fi nal Class< ?> mbeanCl ass = mbea n.getClass ();
  184           Cl ass<? supe r T> c = n ull;
  185           tr y {
  186                c = Util .cast(getS tandardMBe anInterfac e(mbeanCla ss));
  187           }  catch (Not CompliantM BeanExcept ion e) {
  188                // Ignor e exceptio n - we nee d to check  whether
  189                // mbean  is an MXB ean first.
  190           }
  191           if  (c != nul l)
  192                return n ew Standar dMBeanSupp ort(mbean,  c);
  193  
  194           tr y {
  195                c = Util .cast(getM XBeanInter face(mbean Class));
  196           }  catch (Not CompliantM BeanExcept ion e) {
  197                // Ignor e exceptio n - we can not decide  whether m bean was s upposed
  198                // to be  an MBean  or an MXBe an. We wil l call che ckComplian ce()
  199                // to ge nerate the  appropria te excepti on.
  200           }
  201           if  (c != nul l)
  202                return n ew MXBeanS upport(mbe an, c);
  203           ch eckComplia nce(mbeanC lass);
  204           th row new No tCompliant MBeanExcep tion("Not  compliant" ); // not  reached
  205       }
  206  
  207       /**
  208        * Bas ic method  for testin g if a giv en class i s a JMX co mpliant MB ean.
  209        *
  210        * @pa ram baseCl ass The cl ass to be  tested
  211        *
  212        * @re turn <code >null</cod e> if the  MBean is a  DynamicMB ean,
  213        *          the c omputed {@ link javax .managemen t.MBeanInf o} otherwi se.
  214        * @ex ception No tCompliant MBeanExcep tion The s pecified c lass is no t a
  215        *             JM X complian t MBean
  216        */
  217       public  static MB eanInfo te stComplian ce(Class<? > baseClas s)
  218           th rows NotCo mpliantMBe anExceptio n {
  219  
  220           //  --------- ---------- ---------- -
  221           //  --------- ---------- ---------- -
  222  
  223           //  Check if  the MBean  implements  the MBean  or the Dy namic
  224           //  MBean int erface
  225           if  (isDynami c(baseClas s))
  226                return n ull;
  227  
  228           re turn testC ompliance( baseClass,  null);
  229       }
  230  
  231       /**
  232        * Tes ts the giv en interfa ce class f or being a  compliant  MXBean in terface.
  233        * A c ompliant M XBean inte rface is a ny publicl y accessib le interfa ce
  234        * fol lowing the  {@link MX Bean} conv entions.
  235        * @pa ram interf aceClass A n interfac e class to  test for  the MXBean  complianc e
  236        * @th rows NotCo mpliantMBe anExceptio n Thrown w hen the te sted inter face
  237        * is  not public  or contra dicts the  {@link MXB ean} conve ntions.
  238        */
  239       public  static vo id testCom plianceMXB eanInterfa ce(Class<? > interfac eClass)
  240                throws N otComplian tMBeanExce ption {
  241           MX BeanIntros pector.get Instance() .getAnalyz er(interfa ceClass);
  242       }
  243  
  244       /**
  245        * Tes ts the giv en interfa ce class f or being a  compliant  MBean int erface.
  246        * A c ompliant M Bean inter face is an y publicly  accessibl e interfac e
  247        * fol lowing the  {@code MB ean} conve ntions.
  248        * @pa ram interf aceClass A n interfac e class to  test for  the MBean  compliance
  249        * @th rows NotCo mpliantMBe anExceptio n Thrown w hen the te sted inter face
  250        * is  not public  or contra dicts the  {@code MBe an} conven tions.
  251        */
  252       public  static vo id testCom plianceMBe anInterfac e(Class<?>  interface Class)
  253                throws N otComplian tMBeanExce ption{
  254           St andardMBea nIntrospec tor.getIns tance().ge tAnalyzer( interfaceC lass);
  255       }
  256  
  257       /**
  258        * Bas ic method  for testin g if a giv en class i s a JMX co mpliant
  259        * Sta ndard MBea n.  This m ethod is o nly called  by the le gacy code
  260        * in  com.sun.ma nagement.j mx.
  261        *
  262        * @pa ram baseCl ass The cl ass to be  tested.
  263        *
  264        * @pa ram mbeanI nterface t he MBean i nterface t hat the cl ass implem ents,
  265        * or  null if th e interfac e must be  determined  by intros pection.
  266        *
  267        * @re turn the c omputed {@ link javax .managemen t.MBeanInf o}.
  268        * @ex ception No tCompliant MBeanExcep tion The s pecified c lass is no t a
  269        *             JM X complian t Standard  MBean
  270        */
  271       public  static sy nchronized  MBeanInfo
  272                testComp liance(fin al Class<? > baseClas s,
  273                                Cla ss<?> mbea nInterface )
  274                throws N otComplian tMBeanExce ption {
  275           if  (mbeanInt erface ==  null)
  276                mbeanInt erface = g etStandard MBeanInter face(baseC lass);
  277           Re flectUtil. checkPacka geAccess(m beanInterf ace);
  278           MB eanIntrosp ector<?> i ntrospecto r = Standa rdMBeanInt rospector. getInstanc e();
  279           re turn getCl assMBeanIn fo(introsp ector, bas eClass, mb eanInterfa ce);
  280       }
  281  
  282       privat e static < M> MBeanIn fo
  283                getClass MBeanInfo( MBeanIntro spector<M>  introspec tor,
  284                                    Class<?> b aseClass,  Class<?> m beanInterf ace)
  285       throws  NotCompli antMBeanEx ception {
  286           Pe rInterface <M> perInt erface = i ntrospecto r.getPerIn terface(mb eanInterfa ce);
  287           re turn intro spector.ge tClassMBea nInfo(base Class, per Interface) ;
  288       }
  289  
  290       /**
  291        * Get  the MBean  interface  implement ed by a JM X Standard
  292        * MBe an class.  This metho d is only  called by  the legacy
  293        * cod e in "com. sun.manage ment.jmx".
  294        *
  295        * @pa ram baseCl ass The cl ass to be  tested.
  296        *
  297        * @re turn The M Bean inter face imple mented by  the MBean.
  298        *          Retur n <code>nu ll</code>  if the MBe an is a Dy namicMBean ,
  299        *          or if  no MBean  interface  is found.
  300        */
  301       public  static Cl ass<?> get MBeanInter face(Class <?> baseCl ass) {
  302           //  Check if  the given  class impl ements the  MBean int erface
  303           //  or the Dy namic MBea n interfac e
  304           if  (isDynami c(baseClas s)) return  null;
  305           tr y {
  306                return g etStandard MBeanInter face(baseC lass);
  307           }  catch (Not CompliantM BeanExcept ion e) {
  308                return n ull;
  309           }
  310       }
  311  
  312       /**
  313        * Get  the MBean  interface  implement ed by a JM X Standard  MBean cla ss.
  314        *
  315        * @pa ram baseCl ass The cl ass to be  tested.
  316        *
  317        * @re turn The M Bean inter face imple mented by  the Standa rd MBean.
  318        *
  319        * @th rows NotCo mpliantMBe anExceptio n The spec ified clas s is
  320        * not  a JMX com pliant Sta ndard MBea n.
  321        */
  322       public  static <T > Class<?  super T> g etStandard MBeanInter face(Class <T> baseCl ass)
  323           th rows NotCo mpliantMBe anExceptio n {
  324                Class<?  super T> c urrent = b aseClass;
  325                Class<?  super T> m beanInterf ace = null ;
  326                while (c urrent !=  null) {
  327                    mbea nInterface  =
  328                         findMBeanI nterface(c urrent, cu rrent.getN ame());
  329                    if ( mbeanInter face != nu ll) break;
  330                    curr ent = curr ent.getSup erclass();
  331                }
  332                    if ( mbeanInter face != nu ll) {
  333                         return mbe anInterfac e;
  334                } else {
  335                final St ring msg =
  336                    "Cla ss " + bas eClass.get Name() +
  337                    " is  not a JMX  compliant  Standard  MBean";
  338                throw ne w NotCompl iantMBeanE xception(m sg);
  339           }
  340       }
  341  
  342       /**
  343        * Get  the MXBea n interfac e implemen ted by a J MX MXBean  class.
  344        *
  345        * @pa ram baseCl ass The cl ass to be  tested.
  346        *
  347        * @re turn The M XBean inte rface impl emented by  the MXBea n.
  348        *
  349        * @th rows NotCo mpliantMBe anExceptio n The spec ified clas s is
  350        * not  a JMX com pliant MXB ean.
  351        */
  352       public  static <T > Class<?  super T> g etMXBeanIn terface(Cl ass<T> bas eClass)
  353           th rows NotCo mpliantMBe anExceptio n {
  354           tr y {
  355                return M XBeanSuppo rt.findMXB eanInterfa ce(baseCla ss);
  356           }  catch (Exc eption e)  {
  357                throw th rowExcepti on(baseCla ss,e);
  358           }
  359       }
  360  
  361       /*
  362        * --- ---------- ---------- ---------- ---------
  363            PRI D A N E S M   T   ODS
  364        * --- ---------- ---------- ---------- ---------
  365        */
  366  
  367  
  368       /**
  369        * Try  to find t he MBean i nterface c orrespondi ng to the  class aNam e
  370        * - i .e. <i>aNa me</i>MBea n, from wi thin aClas s and its  superclass es.
  371        **/
  372       privat e static < T> Class<?  super T>  findMBeanI nterface(
  373                Class<T>  aClass, S tring aNam e) {
  374           Cl ass<? supe r T> curre nt = aClas s;
  375           wh ile (curre nt != null ) {
  376                final Cl ass<?>[] i nterfaces  = current. getInterfa ces();
  377                final in t len = in terfaces.l ength;
  378                for (int  i=0;i<len ;i++)  {
  379                    Clas s<? super  T> inter =  Util.cast (interface s[i]);
  380                    inte r = implem entsMBean( inter, aNa me);
  381                    if ( inter != n ull) retur n inter;
  382                }
  383                current  = current. getSupercl ass();
  384           }
  385           re turn null;
  386       }
  387  
  388       public  static De scriptor d escriptorF orElement( final Anno tatedEleme nt elmt) {
  389           if  (elmt ==  null)
  390                return I mmutableDe scriptor.E MPTY_DESCR IPTOR;
  391           fi nal Annota tion[] ann ots = elmt .getAnnota tions();
  392           re turn descr iptorForAn notations( annots);
  393       }
  394  
  395       public  static De scriptor d escriptorF orAnnotati ons(Annota tion[] ann ots) {
  396           if  (annots.l ength == 0 )
  397                return I mmutableDe scriptor.E MPTY_DESCR IPTOR;
  398           Ma p<String,  Object> de scriptorMa p = new Ha shMap<Stri ng, Object >();
  399           fo r (Annotat ion a : an nots) {
  400                Class<?  extends An notation>  c = a.anno tationType ();
  401                Method[]  elements  = c.getMet hods();
  402                boolean  packageAcc ess = fals e;
  403                for (Met hod elemen t : elemen ts) {
  404                    Desc riptorKey  key = elem ent.getAnn otation(De scriptorKe y.class);
  405                    if ( key != nul l) {
  406                         String nam e = key.va lue();
  407                         Object val ue;
  408                         try {
  409                             // Avo id checkin g access m ore than o nce per an notation
  410                             if (!p ackageAcce ss) {
  411                                 Re flectUtil. checkPacka geAccess(c );
  412                                 pa ckageAcces s = true;
  413                             }
  414                             value  = MethodUt il.invoke( element, a , null);
  415                         } catch (R untimeExce ption e) {
  416                             // we  don't expe ct this -  except for  possibly
  417                             // sec urity exce ptions?
  418                             // Run timeExcept ions shoul dn't be "U ndeclaredT hrowable".
  419                             // any way...
  420                             //
  421                             throw  e;
  422                         } catch (E xception e ) {
  423                             // we  don't expe ct this
  424                             throw  new Undecl aredThrowa bleExcepti on(e);
  425                         }
  426                         value = an notationTo Field(valu e);
  427                         Object old Value = de scriptorMa p.put(name , value);
  428                         if (oldVal ue != null  && !equal s(oldValue , value))  {
  429                             final  String msg  =
  430                                 "I nconsisten t values f or descrip tor field  " + name +
  431                                 "  from annot ations: "  + value +  " :: " + o ldValue;
  432                             throw  new Illega lArgumentE xception(m sg);
  433                         }
  434                    }
  435                }
  436           }
  437  
  438           if  (descript orMap.isEm pty())
  439                return I mmutableDe scriptor.E MPTY_DESCR IPTOR;
  440           el se
  441                return n ew Immutab leDescript or(descrip torMap);
  442       }
  443  
  444       /**
  445        * Thr ows a NotC ompliantMB eanExcepti on or a Se curityExce ption.
  446        * @pa ram notCom pliant the  class whi ch was und er examina tion
  447        * @pa ram cause  the raeson  why NotCo mpliantMBe anExceptio n should
  448        *         be thr own.
  449        * @re turn nothi ng - this  method alw ays throw  an excepti on.
  450        *          The r eturn type  makes it  possible t o write
  451        *          <pre>  throw thr owExceptio n(clazz,ca use); </pr e>
  452        * @th rows Secur ityExcepti on - if ca use is a S ecurityExc eption
  453        * @th rows NotCo mpliantMBe anExceptio n otherwis e.
  454        **/
  455       static  NotCompli antMBeanEx ception th rowExcepti on(Class<? > notCompl iant,
  456                Throwabl e cause)
  457                throws N otComplian tMBeanExce ption, Sec urityExcep tion {
  458           if  (cause in stanceof S ecurityExc eption)
  459                throw (S ecurityExc eption) ca use;
  460           if  (cause in stanceof N otComplian tMBeanExce ption)
  461                throw (N otComplian tMBeanExce ption)caus e;
  462           fi nal String  classname  =
  463                    (not Compliant= =null)?"nu ll class": notComplia nt.getName ();
  464           fi nal String  reason =
  465                    (cau se==null)? "Not compl iant":caus e.getMessa ge();
  466           fi nal NotCom pliantMBea nException  res =
  467                    new  NotComplia ntMBeanExc eption(cla ssname+":  "+reason);
  468           re s.initCaus e(cause);
  469           th row res;
  470       }
  471  
  472       // Con vert a val ue from an  annotatio n element  to a descr iptor fiel d value
  473       // E.g . with @in terface Fo o {class v alue()} an  annotatio n @Foo(Str ing.class)
  474       // wil l produce  a Descript or field v alue "java .lang.Stri ng"
  475       privat e static O bject anno tationToFi eld(Object  x) {
  476           //  An annota tion eleme nt cannot  have a nul l value bu t never mi nd
  477           if  (x == nul l)
  478                return n ull;
  479           if  (x instan ceof Numbe r || x ins tanceof St ring ||
  480                    x in stanceof C haracter | | x instan ceof Boole an ||
  481                    x in stanceof S tring[])
  482                return x ;
  483           //  Remaining  possibili ties: arra y of primi tive (e.g.  int[]),
  484           //  enum, cla ss, array  of enum or  class.
  485           Cl ass<?> c =  x.getClas s();
  486           if  (c.isArra y()) {
  487                if (c.ge tComponent Type().isP rimitive() )
  488                    retu rn x;
  489                Object[]  xx = (Obj ect[]) x;
  490                String[]  ss = new  String[xx. length];
  491                for (int  i = 0; i  < xx.lengt h; i++)
  492                    ss[i ] = (Strin g) annotat ionToField (xx[i]);
  493                return s s;
  494           }
  495           if  (x instan ceof Class <?>)
  496                return ( (Class<?>)  x).getNam e();
  497           if  (x instan ceof Enum< ?>)
  498                return ( (Enum<?>)  x).name();
  499           //  The only  other poss ibility is  that the  value is a nother
  500           //  annotatio n, or that  the langu age has ev olved sinc e this cod e
  501           //  was writt en.  We do n't allow  for either  of those  currently.
  502           //  If it is  indeed ano ther annot ation, the n x will b e a proxy
  503           //  with an u nhelpful n ame like $ Proxy2.  S o we extra ct the
  504           //  proxy's i nterface t o use that  in the ex ception me ssage.
  505           if  (Proxy.is ProxyClass (c))
  506                c = c.ge tInterface s()[0];  / / array "c an't be em pty"
  507           th row new Il legalArgum entExcepti on("Illega l type for  annotatio n " +
  508                    "ele ment using  @Descript orKey: " +  c.getName ());
  509       }
  510  
  511       // Thi s must be  consistent  with the  check for  duplicate  field valu es in
  512       // Imm utableDesc riptor.uni on.  But w e don't ex pect to be  called ve ry
  513       // oft en so this  inefficie nt check s hould be e nough.
  514       privat e static b oolean equ als(Object  x, Object  y) {
  515           re turn Array s.deepEqua ls(new Obj ect[] {x},  new Objec t[] {y});
  516       }
  517  
  518       /**
  519        * Ret urns the X XMBean int erface or  null if no  such inte rface exis ts
  520        *
  521        * @pa ram c The  interface  to be test ed
  522        * @pa ram clName  The name  of the cla ss impleme nting this  interface
  523        */
  524       privat e static < T> Class<?  super T>  implements MBean(Clas s<T> c, St ring clNam e) {
  525           St ring clMBe anName = c lName + "M Bean";
  526           if  (c.getNam e().equals (clMBeanNa me)) {
  527                return c ;
  528           }
  529           Cl ass<?>[] i nterfaces  = c.getInt erfaces();
  530           fo r (int i =  0;i < int erfaces.le ngth; i++)  {
  531                if (inte rfaces[i]. getName(). equals(clM BeanName)  &&
  532                    (Mod ifier.isPu blic(inter faces[i].g etModifier s()) ||
  533                     ALL OW_NONPUBL IC_MBEAN))  {
  534                    retu rn Util.ca st(interfa ces[i]);
  535                }
  536           }
  537  
  538           re turn null;
  539       }
  540  
  541       public  static Ob ject eleme ntFromComp lex(Object  complex,  String ele ment)
  542       throws  Attribute NotFoundEx ception {
  543           tr y {
  544                if (comp lex.getCla ss().isArr ay() && el ement.equa ls("length ")) {
  545                    retu rn Array.g etLength(c omplex);
  546                } else i f (complex  instanceo f Composit eData) {
  547                    retu rn ((Compo siteData)  complex).g et(element );
  548                } else {
  549                    // J ava Beans  introspect ion
  550                    //
  551                    Clas s<?> clazz  = complex .getClass( );
  552                    Meth od readMet hod = null ;
  553                    if ( BeansHelpe r.isAvaila ble()) {
  554                         Object bi  = BeansHel per.getBea nInfo(claz z);
  555                         Object[] p ds = Beans Helper.get PropertyDe scriptors( bi);
  556                         for (Objec t pd: pds)  {
  557                             if (Be ansHelper. getPropert yName(pd). equals(ele ment)) {
  558                                 re adMethod =  BeansHelp er.getRead Method(pd) ;
  559                                 br eak;
  560                             }
  561                         }
  562                    } el se {
  563                         // Java Be ans not av ailable so  use simpl e introspe ction
  564                         // to loca te method
  565                         readMethod  = SimpleI ntrospecto r.getReadM ethod(claz z, element );
  566                    }
  567                    if ( readMethod  != null)  {
  568                         ReflectUti l.checkPac kageAccess (readMetho d.getDecla ringClass( ));
  569                         return Met hodUtil.in voke(readM ethod, com plex, new  Class[0]);
  570                    }
  571  
  572                    thro w new Attr ibuteNotFo undExcepti on(
  573                         "Could not  find the  getter met hod for th e property  " +
  574                         element +  " using th e Java Bea ns introsp ector");
  575                }
  576           }  catch (Inv ocationTar getExcepti on e) {
  577                throw ne w IllegalA rgumentExc eption(e);
  578           }  catch (Att ributeNotF oundExcept ion e) {
  579                throw e;
  580           }  catch (Exc eption e)  {
  581                throw En vHelp.init Cause(
  582                    new  AttributeN otFoundExc eption(e.g etMessage( )), e);
  583           }
  584       }
  585  
  586       /**
  587        * A s imple intr ospector t hat uses r eflection  to analyze  a class a nd
  588        * ide ntify its  "getter" m ethods. Th is class i s intended  for use o nly when
  589        * Jav a Beans is  not prese nt (which  implies th at there i sn't expli cit
  590        * inf ormation a bout the b ean availa ble).
  591        */
  592       privat e static c lass Simpl eIntrospec tor {
  593           pr ivate Simp leIntrospe ctor() { }
  594  
  595           pr ivate stat ic final S tring GET_ METHOD_PRE FIX = "get ";
  596           pr ivate stat ic final S tring IS_M ETHOD_PREF IX = "is";
  597  
  598           //  cache to  avoid repe ated looku ps
  599           pr ivate stat ic final M ap<Class<? >,SoftRefe rence<List <Method>>>  cache =
  600                Collecti ons.synchr onizedMap(
  601                    new  WeakHashMa p<Class<?> ,SoftRefer ence<List< Method>>>  ());
  602  
  603           /* *
  604            *  Returns t he list of  methods c ached for  the given  class, or  {@code nul l}
  605            *  if not ca ched.
  606            * /
  607           pr ivate stat ic List<Me thod> getC achedMetho ds(Class<? > clazz) {
  608                // retur n cached m ethods if  possible
  609                SoftRefe rence<List <Method>>  ref = cach e.get(claz z);
  610                if (ref  != null) {
  611                    List <Method> c ached = re f.get();
  612                    if ( cached !=  null)
  613                         return cac hed;
  614                }
  615                return n ull;
  616           }
  617  
  618           /* *
  619            *  Returns { @code true } if the g iven metho d is a "ge tter" meth od (where
  620            *  "getter"  method is  a public m ethod of t he form ge tXXX or "b oolean
  621            *  isXXX")
  622            * /
  623           st atic boole an isReadM ethod(Meth od method)  {
  624                // ignor e static m ethods
  625                int modi fiers = me thod.getMo difiers();
  626                if (Modi fier.isSta tic(modifi ers))
  627                    retu rn false;
  628  
  629                String n ame = meth od.getName ();
  630                Class<?> [] paramTy pes = meth od.getPara meterTypes ();
  631                int para mCount = p aramTypes. length;
  632  
  633                if (para mCount ==  0 && name. length() >  2) {
  634                    // b oolean isX XX()
  635                    if ( name.start sWith(IS_M ETHOD_PREF IX))
  636                         return (me thod.getRe turnType()  == boolea n.class);
  637                    // g etXXX()
  638                    if ( name.lengt h() > 3 &&  name.star tsWith(GET _METHOD_PR EFIX))
  639                         return (me thod.getRe turnType()  != void.c lass);
  640                }
  641                return f alse;
  642           }
  643  
  644           /* *
  645            *  Returns t he list of  "getter"  methods fo r the give n class. T he list
  646            *  is ordere d so that  isXXX meth ods appear  before ge tXXX metho ds - this
  647            *  is for co mpatibilit y with the  JavaBeans  Introspec tor.
  648            * /
  649           st atic List< Method> ge tReadMetho ds(Class<? > clazz) {
  650                // retur n cached r esult if a vailable
  651                List<Met hod> cache dResult =  getCachedM ethods(cla zz);
  652                if (cach edResult ! = null)
  653                    retu rn cachedR esult;
  654  
  655                // get l ist of pub lic method s, filteri ng out met hods that  have
  656                // been  overridden  to return  a more sp ecific typ e.
  657                List<Met hod> metho ds =
  658                    Stan dardMBeanI ntrospecto r.getInsta nce().getM ethods(cla zz);
  659                methods  = MBeanAna lyzer.elim inateCovar iantMethod s(methods) ;
  660  
  661                // filte r out the  non-getter  methods
  662                List<Met hod> resul t = new Li nkedList<M ethod>();
  663                for (Met hod m: met hods) {
  664                    if ( isReadMeth od(m)) {
  665                         // favor i sXXX over  getXXX
  666                         if (m.getN ame().star tsWith(IS_ METHOD_PRE FIX)) {
  667                             result .add(0, m) ;
  668                         } else {
  669                             result .add(m);
  670                         }
  671                    }
  672                }
  673  
  674                // add r esult to c ache
  675                cache.pu t(clazz, n ew SoftRef erence<Lis t<Method>> (result));
  676  
  677                return r esult;
  678           }
  679  
  680           /* *
  681            *  Returns t he "getter " to read  the given  property f rom the gi ven class  or
  682            *  {@code nu ll} if no  method is  found.
  683            * /
  684           st atic Metho d getReadM ethod(Clas s<?> clazz , String p roperty) {
  685                // first  character  in upperc ase (compa tibility w ith JavaBe ans)
  686                property  = propert y.substrin g(0, 1).to UpperCase( Locale.ENG LISH) +
  687                    prop erty.subst ring(1);
  688                String g etMethod =  GET_METHO D_PREFIX +  property;
  689                String i sMethod =  IS_METHOD_ PREFIX + p roperty;
  690                for (Met hod m: get ReadMethod s(clazz))  {
  691                    Stri ng name =  m.getName( );
  692                    if ( name.equal s(isMethod ) || name. equals(get Method)) {
  693                         return m;
  694                    }
  695                }
  696                return n ull;
  697           }
  698       }
  699  
  700       /**
  701        * A c lass that  provides a ccess to t he JavaBea ns Introsp ector and
  702        * Pro pertyDescr iptors wit hout creat ing a stat ic depende ncy on jav a.beans.
  703        */
  704       privat e static c lass Beans Helper {
  705           pr ivate stat ic final C lass<?> in trospector Class =
  706                getClass ("java.bea ns.Introsp ector");
  707           pr ivate stat ic final C lass<?> be anInfoClas s =
  708                (introsp ectorClass  == null)  ? null : g etClass("j ava.beans. BeanInfo") ;
  709           pr ivate stat ic final C lass<?> ge tPropertyD escriptorC lass =
  710                (beanInf oClass ==  null) ? nu ll : getCl ass("java. beans.Prop ertyDescri ptor");
  711  
  712           pr ivate stat ic final M ethod getB eanInfo =
  713                getMetho d(introspe ctorClass,  "getBeanI nfo", Clas s.class);
  714           pr ivate stat ic final M ethod getP ropertyDes criptors =
  715                getMetho d(beanInfo Class, "ge tPropertyD escriptors ");
  716           pr ivate stat ic final M ethod getP ropertyNam e =
  717                getMetho d(getPrope rtyDescrip torClass,  "getName") ;
  718           pr ivate stat ic final M ethod getR eadMethod  =
  719                getMetho d(getPrope rtyDescrip torClass,  "getReadMe thod");
  720  
  721           pr ivate stat ic Class<? > getClass (String na me) {
  722                try {
  723                    retu rn Class.f orName(nam e, true, n ull);
  724                } catch  (ClassNotF oundExcept ion e) {
  725                    retu rn null;
  726                }
  727           }
  728           pr ivate stat ic Method  getMethod( Class<?> c lazz,
  729                                               String nam e,
  730                                               Class<?>.. . paramTyp es)
  731           {
  732                if (claz z != null)  {
  733                    try  {
  734                         return cla zz.getMeth od(name, p aramTypes) ;
  735                    } ca tch (NoSuc hMethodExc eption e)  {
  736                         throw new  AssertionE rror(e);
  737                    }
  738                } else {
  739                    retu rn null;
  740                }
  741           }
  742  
  743           pr ivate Bean sHelper()  { }
  744  
  745           /* *
  746            *  Returns { @code true } if java. beans is a vailable.
  747            * /
  748           st atic boole an isAvail able() {
  749                return i ntrospecto rClass !=  null;
  750           }
  751  
  752           /* *
  753            *  Invokes j ava.beans. Introspect or.getBean Info(Class )
  754            * /
  755           st atic Objec t getBeanI nfo(Class< ?> clazz)  throws Exc eption {
  756                try {
  757                    retu rn getBean Info.invok e(null, cl azz);
  758                } catch  (Invocatio nTargetExc eption e)  {
  759                    Thro wable caus e = e.getC ause();
  760                    if ( cause inst anceof Exc eption)
  761                         throw (Exc eption)cau se;
  762                    thro w new Asse rtionError (e);
  763                } catch  (IllegalAc cessExcept ion iae) {
  764                    thro w new Asse rtionError (iae);
  765                }
  766           }
  767  
  768           /* *
  769            *  Invokes j ava.beans. BeanInfo.g etProperty Descriptor s()
  770            * /
  771           st atic Objec t[] getPro pertyDescr iptors(Obj ect bi) {
  772                try {
  773                    retu rn (Object [])getProp ertyDescri ptors.invo ke(bi);
  774                } catch  (Invocatio nTargetExc eption e)  {
  775                    Thro wable caus e = e.getC ause();
  776                    if ( cause inst anceof Run timeExcept ion)
  777                         throw (Run timeExcept ion)cause;
  778                    thro w new Asse rtionError (e);
  779                } catch  (IllegalAc cessExcept ion iae) {
  780                    thro w new Asse rtionError (iae);
  781                }
  782           }
  783  
  784           /* *
  785            *  Invokes j ava.beans. PropertyDe scriptor.g etName()
  786            * /
  787           st atic Strin g getPrope rtyName(Ob ject pd) {
  788                try {
  789                    retu rn (String )getProper tyName.inv oke(pd);
  790                } catch  (Invocatio nTargetExc eption e)  {
  791                    Thro wable caus e = e.getC ause();
  792                    if ( cause inst anceof Run timeExcept ion)
  793                         throw (Run timeExcept ion)cause;
  794                    thro w new Asse rtionError (e);
  795                } catch  (IllegalAc cessExcept ion iae) {
  796                    thro w new Asse rtionError (iae);
  797                }
  798           }
  799  
  800           /* *
  801            *  Invokes j ava.beans. PropertyDe scriptor.g etReadMeth od()
  802            * /
  803           st atic Metho d getReadM ethod(Obje ct pd) {
  804                try {
  805                    retu rn (Method )getReadMe thod.invok e(pd);
  806                } catch  (Invocatio nTargetExc eption e)  {
  807                    Thro wable caus e = e.getC ause();
  808                    if ( cause inst anceof Run timeExcept ion)
  809                         throw (Run timeExcept ion)cause;
  810                    thro w new Asse rtionError (e);
  811                } catch  (IllegalAc cessExcept ion iae) {
  812                    thro w new Asse rtionError (iae);
  813                }
  814           }
  815       }
  816   }