changeset 6514:91cdaff2fed3

8011038: sourceObj validation during desereliazation of RelationNotification should be relaxed Summary: sourceObj could be set to null by setSource() relax a validation of deserialized object. Reviewed-by: sjiang, skoivu, dfuchs
author dsamersoff
date Tue, 06 Aug 2013 17:37:41 +0400
parents c9e42ad7fb24
children 9c037838185c
files src/share/classes/javax/management/relation/RelationNotification.java
diffstat 1 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/management/relation/RelationNotification.java	Fri Aug 02 17:57:00 2013 +0400
+++ b/src/share/classes/javax/management/relation/RelationNotification.java	Tue Aug 06 17:37:41 2013 +0400
@@ -260,7 +260,7 @@
 
         super(notifType, sourceObj, sequence, timeStamp, message);
 
-        if (!isValidBasic(notifType,sourceObj,id,typeName) || !isValidCreate(notifType)) {
+        if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidCreate(notifType)) {
             throw new IllegalArgumentException("Invalid parameter.");
         }
 
@@ -310,7 +310,7 @@
 
         super(notifType, sourceObj, sequence, timeStamp, message);
 
-        if (!isValidBasic(notifType,sourceObj,id,typeName) || !isValidUpdate(notifType,name,newValue,oldValue)) {
+        if (!isValidBasicStrict(notifType,sourceObj,id,typeName) || !isValidUpdate(notifType,name,newValue,oldValue)) {
             throw new IllegalArgumentException("Invalid parameter.");
         }
 
@@ -457,14 +457,26 @@
     //  - no role old value (for role update)
     //  - no role new value (for role update)
 
+    // Despite the fact, that validation in constructor of RelationNotification prohibit
+    // creation of the class instance with null sourceObj its possible to set it to null later
+    // by public setSource() method.
+    // So we should relax validation rules to preserve serialization behavior compatibility.
+
+    private boolean isValidBasicStrict(String notifType, Object sourceObj, String id, String typeName){
+        if (sourceObj == null) {
+            return false;
+        }
+        return isValidBasic(notifType,sourceObj,id,typeName);
+    }
+
     private boolean isValidBasic(String notifType, Object sourceObj, String id, String typeName){
-        if (notifType == null || sourceObj == null ||
-            id == null || typeName == null) {
+        if (notifType == null || id == null || typeName == null) {
             return false;
         }
 
-        if (!(sourceObj instanceof RelationService) &&
-            !(sourceObj instanceof ObjectName)) {
+        if (sourceObj != null && (
+            !(sourceObj instanceof RelationService) &&
+            !(sourceObj instanceof ObjectName))) {
             return false;
         }