JDK-6783290 : MBeanInfo/MBeanFeatureInfo has inconsistent readObject/writeObject
  • Type: Bug
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2008-12-10
  • Updated: 2014-01-15
  • Resolved: 2012-12-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b71Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
Since the addition of Descriptors to all kinds of MBeanInfo (rather than just ModelMBeanInfo as before), an inconsistency has appeared in the serialization of MBeanFeatureInfo when its Descriptor is an empty ImmutableDescriptor.

MBeanFeatureInfo.writeObject(ObjectOutputStream out) does the following in this case:

	    out.write(1);

	    final String[] names = descriptor.getFieldNames();

	    out.writeObject(names);
	    out.writeObject(descriptor.getFieldValues(names));

MBeanFeatureInfo.readObject(ObjectInputStream in) does this:

	switch (in.read()) {
	case 1:
	    final String[] names = (String[])in.readObject();

	    if (names.length == 0) {
		descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR;
	    } else {
		final Object[] values = (Object[])in.readObject();
		descriptor = new ImmutableDescriptor(names, values);
	    }

The problem is that when names.length == 0 we do not read the zero-length Object[] written by out.writeObject(descriptor.getFieldValues(names)).  The serialization specification is unclear as to what happens when a readObject does not consume all the "optional data".  Native serialization (as used by RMI/JRMP) just discards the unread data, but RMI/IIOP implementations might not.

Comments
Fix pushed: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/b600d490dc57
20-12-2012

EVALUATION MBeanInfo has exactly the same code and must be fixed at the same time.
12-12-2008

SUGGESTED FIX Replace this code from writeObject... if (names.length == 0) { descriptor = ImmutableDescriptor.EMPTY_DESCRIPTOR; } else { final Object[] values = (Object[])in.readObject(); descriptor = new ImmutableDescriptor(names, values); } ...with this... final Object[] values = (Object[]) in.readObject(); descriptor = (names.length == 0) ? ImmutableDescriptor.EMPTY_DESCRIPTOR : new ImmutableDescriptor(names, values);
10-12-2008

WORK AROUND Avoid empty ImmutableDescriptor, using either null or an empty DescriptorSupport instead.
10-12-2008

EVALUATION Obviously we should fix this. The choice is between not writing the extra data that will not be read or reading the extra data that was previously unread. The specification of the readObject and writeObject methods does not mention a special case for zero-length Descriptors, so following the spec we should read the empty descriptor (before replacing it with ImmutableDescriptor.EMPTY_DESCRIPTOR).
10-12-2008