changeset 4923:d6cdeea8b194

8009038: Improve JMX notification support Summary: Disallowing access to mutable shared arrays Reviewed-by: dfuchs, mchung, skoivu
author jbachorik
date Tue, 12 Mar 2013 09:34:26 +0100
parents 8f3def9cab48
children 1b844fe1bb58
files src/share/classes/javax/management/StandardEmitterMBean.java
diffstat 1 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/management/StandardEmitterMBean.java	Tue Mar 12 11:09:37 2013 +0100
+++ b/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();
+        }
     }
 
     /**