Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-5050118

ModelMBeanInfoSupport overwrites MBeanDescriptor value for visibility

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.2
    • core-svc

      Name: jl125535 Date: 05/19/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_02"
      Version = J2EE(TM) Application Server 1.4 Developer Release

      A DESCRIPTION OF THE PROBLEM :
      I created a ModelMBeanInfo object by instantiating a ModelMBeanInfoSupport object. I then retrieved the default MBean Descriptor object. By default the descriptor has the visibility field set to "1". I then set the visisbility field to "4". Next, I called the setMBeanDescriptor and provided the modified descriptor. The ModelMBeanInfoSupport object incorrectly reset the visibility value back to "1".

      It appears that the underlying problem is that the MBeanDescriptor visibility field is misspelt as "visiblity".

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the test case below.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Please view code.
      ACTUAL -
      Please view code.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.management.*;
      import javax.management.modelmbean.*;

      public class JMXTest {
          public JMXTest() {}
          public static void main(String[] args) {
              // create MBean info
              ModelMBeanInfo mBeanInfo = new ModelMBeanInfoSupport("Object",
                  "Description", null, null, null, null);
              // get the default descriptor
              try {
                  Descriptor descriptor = mBeanInfo.getMBeanDescriptor();
                  // verify that the default value for visibility is "1"
                  System.out.println("Default visibility setting (should be 1): " +
                                     descriptor.getFieldValue("visibility"));
                  // change the value of the visibility field
                  descriptor.setField("visibility", "4");
                  // verify that the descriptor visibility field is indeed "4"
                  System.out.println("New visibility setting (should be 4): " +
                                     descriptor.getFieldValue("visibility"));
                  // reset the descriptor on the ModelMBeanInfo
                  mBeanInfo.setMBeanDescriptor(descriptor);
                  // retrive the descriptor again
                  descriptor = mBeanInfo.getMBeanDescriptor();
                  // show that it is set back to "1" and is not "4"
                  System.out.println(
                      "Incorrect visibility setting (should be 4 but is 1): "
                      + descriptor.getFieldValue("visibility"));
                  // a work around:
                  // I found that during a field validation check as the
                  // descriptor is being set there is a spelling error.
                  // visibility is spelled visiblity (missing an i)
                  // this work around will changed the value to "4"

                  // change the value of the visibility field
                  descriptor.setField("visibility", "4");
                  // now also add the incorrect spelling
                  descriptor.setField("visiblity", "4");
                  // verify that the descriptor visibility field is indeed "4"
                  System.out.println("New visibility setting (should be 4): " +
                                     descriptor.getFieldValue("visibility"));
                  System.out.println("Misspelled visiblity setting (should be 4): " +
                                     descriptor.getFieldValue("visiblity"));
                  // reset the descriptor on the ModelMBeanInfo
                  mBeanInfo.setMBeanDescriptor(descriptor);
                  // retrive the descriptor again
                  descriptor = mBeanInfo.getMBeanDescriptor();
                  // This time the value is set correctly to "4"
                  System.out.println(
                     "Correct visibility setting due to work around (should be 4)): "
                     + descriptor.getFieldValue("visibility"));
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Please review source. It shows the bug and work around.
      (Incident Review ID: 237558)
      ======================================================================

            jfdenise Jean-Francois Denise (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: