United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4892674 : javax.management.relation.RelationNotification fails to be serialized

Details
Type:
Bug
Submit Date:
2003-07-18
Status:
Resolved
Updated Date:
2005-12-03
Project Name:
JDK
Resolved Date:
2005-12-03
Component:
core-svc
OS:
linux,solaris_2.6,solaris_10,windows_2003
Sub-Component:
javax.management
CPU:
x86,sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:

Related Reports

Sub Tasks

Description
Name: ygR10224			Date: 07/18/2003


Filed By      : SPB JCK team (###@###.###)
JDK           : java full version "1.5.0-beta-b10"
JCK           : 1.5
Platform[s]   : Solaris
switch/Mode   : 
JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
Failing Test [s] : N/A


Problem description
===================
In spite of the javax.management.relation.RelationNotification implementing 
the java.io.Serializable interface it can't be serialized.
    
Minimized test:
===============
------- Test.java -------
import java.io.*;
import javax.management.*;
import javax.management.relation.*;

public class Test {

    public static void main(String[] args) throws Exception {
        javax.management.ObjectName relobj = new javax.management.ObjectName("domain:key=value");
        java.util.List nrv = new java.util.ArrayList();
        java.util.List orv = new java.util.ArrayList();
        nrv.add(new javax.management.ObjectName("domain1:key1=value1"));
        orv.add(new javax.management.ObjectName("domain2:key2=value2"));

        RelationNotification obj = new javax.management.relation.RelationNotification(
                javax.management.relation.RelationNotification.RELATION_BASIC_UPDATE, 
                new javax.management.relation.RelationService(true), 
                1L, 2L, "message", "relationId", "relationTypeName", 
                relobj, "roleName", nrv, orv);
        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream("RelationNotification.ser"));
        oos.writeObject(obj);
        oos.close();
    }
    
}
------- end-of-Test.java -------

Minimized test output:
======================
<gyi@helmet(pts/13).268> java Test
Exception in thread "main" java.io.NotSerializableException: javax.management.relation.RelationService
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)
        at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1332)
        at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:367)
        at javax.management.Notification.writeObject(Notification.java:371)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:324)
        at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:809)
        at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1296)
        at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1247)
        at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)
        at Test.main(Test.java:21)

Specific Machine Info:
=====================
SunOS helmet 5.8 Generic_108528-14 sun4u sparc SUNW,Ultra-2

======================================================================

                                    

Comments
EVALUATION

I am proposing to accept an instance of either RelationService or ObjectName in the constructor.  Serialization tests can use the latter.
                                     
2005-11-07
PUBLIC COMMENTS

.
                                     
2004-09-01
EVALUATION

This is not a bug.  Part of the serialized form of a RelationNotification is its source.  In the test code, the source is a RelationService, which is not a serializable object.  It should be an ObjectName.
###@###.### 2003-08-21

According to the spec:                                                          
        "theSrcObj - source object, sending the notification. Will always be a  
RelationService object.".                                                       
In fact, an implementation of RelationNotification just throws IAE in case      
something except RelationService is passed as the source object. How the test   
code can put there ObjectName instead of RelationService?                       
 
###@###.### 2003-09-02

In fact, the specification is misleading.  When the RelationNotification object is constructed, it is indeed given a RelationService object as an argument.  However, when the RelationService subsequently emits that notification, the MBean server replaces the source with the ObjectName of the RelationService.  This is defined JMX behaviour: when a Notification emitted by MBean X contains the object X as its source, the MBean server replaces X in the notification by X's ObjectName.

The correct fix would be to clarify the specification.  However, since this is part of the JMX 1.2 implementation, we cannot strictly do that without doing a Maintenance Release of JMX.  We can probably make exceptions for very important cases, but this is not one of them.  Therefore, I'm suggesting either that this bug be closed, or that its priority be reduced.  It may be better to close this bug and file a new one against the JMX documentation with priority 4 or 5.
###@###.### 2003-09-03

I'm reassigning this bug since I am unable to go further with it as it stands.
###@###.### 2003-09-25

Name: acR10002			Date: 09/25/2003

OK. If you agree this is a spec bug, then could you please reassign this bug to the appropriate tech/spec writer person? I'm not sure I can handle this in 
either way, I'm even not in the JMX team. I'm OK with that bug is fixed
in later releases. This is new JCK tests, hence "No  regression" rule
doesn't apply.

======================================================================
                                     
2004-09-01
WORK AROUND

If the purpose of the test is to check that serialization of a RelationNotification is compatible, this could be done by creating a class like this:

package com.sun.whatever;
import javax.management.relation.RelationService;
import java.io.*;
public class SerializableRelationService extends RelationService implements Externalizable {
    public SerializableRelationService() {
        super(true);
    }
    public void writeExternal(ObjectOutput out) {}
    public void readExternal(ObjectInput in) {}
}

Then an instance of RelationNotification can be constructed with a SerializableRelationService as its source, and that should be sufficient to test serialization compatibility.
###@###.### 2003-11-03

Yuri Gayevski points out that there is a much simpler solution.  Construct a RelationService object, use it as the source when constructing a RelationNotification, then change the source to an ObjectName using RelationNotification.setSource.  This works, and corresponds to what the MBean server does when forwarding a RelationNotification.

This is in fact what the serialization test in the standalone JMX TCK does.  Even though I wrote that test, I had forgotten it when I suggested the other workaround.
###@###.### 2003-11-04
                                     
2003-11-04
SUGGESTED FIX

Allow the source of a RelationNotification to be either a RelationService object or an ObjectName (which is expected but not required to name a RelationService object).  The serialization test should then use an ObjectName.  It is proposed that this be done in the next version of JMX, which would be in the J2SE 1.6 timeframe.  We will add it to the list of Proposed Changes for that version of JMX.
###@###.### 2003-11-03
                                     
2003-11-03



Hardware and Software, Engineered to Work Together