8009038: Improve JMX notification support
authorjbachorik
Tue, 12 Mar 2013 09:34:26 +0100
changeset 18188 48e73ecb2461
parent 18187 a798516cf58d
child 18189 ef33730f6b2b
8009038: Improve JMX notification support Summary: Disallowing access to mutable shared arrays Reviewed-by: dfuchs, mchung, skoivu
jdk/src/share/classes/javax/management/StandardEmitterMBean.java
--- a/jdk/src/share/classes/javax/management/StandardEmitterMBean.java	Thu Mar 07 14:05:05 2013 +0100
+++ b/jdk/src/share/classes/javax/management/StandardEmitterMBean.java	Tue Mar 12 09:34:26 2013 +0100
@@ -64,6 +64,9 @@
 public class StandardEmitterMBean extends StandardMBean
         implements NotificationEmitter {
 
+    private static final MBeanNotificationInfo[] NO_NOTIFICATION_INFO =
+        new MBeanNotificationInfo[0];
+
     private final NotificationEmitter emitter;
     private final MBeanNotificationInfo[] notificationInfo;
 
@@ -99,11 +102,7 @@
      */
     public <T> StandardEmitterMBean(T implementation, Class<T> mbeanInterface,
                                     NotificationEmitter emitter) {
-        super(implementation, mbeanInterface, false);
-        if (emitter == null)
-            throw new IllegalArgumentException("Null emitter");
-        this.emitter = emitter;
-        this.notificationInfo = emitter.getNotificationInfo();
+        this(implementation, mbeanInterface, false, emitter);
     }
 
     /**
@@ -148,7 +147,12 @@
         if (emitter == null)
             throw new IllegalArgumentException("Null emitter");
         this.emitter = emitter;
-        this.notificationInfo = emitter.getNotificationInfo();
+        MBeanNotificationInfo[] infos = emitter.getNotificationInfo();
+        if (infos == null || infos.length == 0) {
+            this.notificationInfo = NO_NOTIFICATION_INFO;
+        } else {
+            this.notificationInfo = infos.clone();
+        }
     }
 
     /**
@@ -184,11 +188,7 @@
      */
     protected StandardEmitterMBean(Class<?> mbeanInterface,
                                    NotificationEmitter emitter) {
-        super(mbeanInterface, false);
-        if (emitter == null)
-            throw new IllegalArgumentException("Null emitter");
-        this.emitter = emitter;
-        this.notificationInfo = emitter.getNotificationInfo();
+        this(mbeanInterface, false, emitter);
     }
 
     /**
@@ -231,7 +231,12 @@
         if (emitter == null)
             throw new IllegalArgumentException("Null emitter");
         this.emitter = emitter;
-        this.notificationInfo = emitter.getNotificationInfo();
+        MBeanNotificationInfo[] infos = emitter.getNotificationInfo();
+        if (infos == null || infos.length == 0) {
+            this.notificationInfo = NO_NOTIFICATION_INFO;
+        } else {
+            this.notificationInfo = infos.clone();
+        }
     }
 
     public void removeNotificationListener(NotificationListener listener)
@@ -253,7 +258,11 @@
     }
 
     public MBeanNotificationInfo[] getNotificationInfo() {
-        return notificationInfo;
+        if (notificationInfo.length == 0) {
+            return notificationInfo;
+        } else {
+            return notificationInfo.clone();
+        }
     }
 
     /**