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

JSR003 - MBeanServerFactory.releaseMBeanServer does not always throw IAE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.2.1
    • core-svc
    • b32
    • unknown
    • generic
    • Verified

      The following piece of Java code is enough to understand the problem.
      Side effect is the user can not discriminate case the mbeanServer argument is faked from the 3 cases listed below.


      /* COPY/PASTE OF THE JAVADOC OF javax/management.MBeanServerFactory.releaseMBeanServer()

      releaseMBeanServer

      public static void releaseMBeanServer(MBeanServer mbeanServer)

          Remove internal MBeanServerFactory references to a created MBeanServer. This allows the garbage collector to remove the MBeanServer object.

          Parameters:
              mbeanServer - the MBeanServer object to remove.
          Throws:
              java.lang.IllegalArgumentException - if mbeanServer was not generated by one of the createMBeanServer methods, or if releaseMBeanServer was already called on it.
              java.lang.SecurityException - if there is a SecurityManager and the caller's permissions do not include or imply MBeanServerPermission("releaseMBeanServer").
      */


      import javax.management.* ;

      public class MBS
      {
          public void run(String args[]) {
                  MBeanServer mbs = MBeanServerFactory.newMBeanServer() ;
                  
                  try {
                      System.out.println("1 - release called after new") ;
                      MBeanServerFactory.releaseMBeanServer(mbs) ;
                      System.out.println("I did not receive any IllegalArgumentException ==> BUG") ;
                  } catch(Exception e) {
                      e.printStackTrace() ;
                  }
                  
                  try {
                      System.out.println("2 - release called twice after new") ;
                      MBeanServerFactory.releaseMBeanServer(mbs) ;
                      System.out.println("I did not receive any IllegalArgumentException ==> BUG") ;
                  } catch(Exception e) {
                      e.printStackTrace() ;
                  }
                  
                  MBeanServer mbs2 = MBeanServerFactory.createMBeanServer() ;
                  
                  try {
                      System.out.println("3 - release called twice after create") ;
                      MBeanServerFactory.releaseMBeanServer(mbs2) ;
                      MBeanServerFactory.releaseMBeanServer(mbs2) ;
                      System.out.println("3 did not receive any IllegalArgumentException ==> BUG") ;
                  } catch(Exception e) {
                      e.printStackTrace() ;
                  }
          }
          
          
          public static void main (String args[]) {
              MBS instance = new MBS();
              instance.run(args);
          }
      }

            lmalvent Luis-Miguel Alventosa (Inactive)
            yjoan Yves Joan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: