Skip to content

Commit

Permalink
8334165: Remove serialVersionUID compatibility logic from JMX
Browse files Browse the repository at this point in the history
Reviewed-by: dfuchs
  • Loading branch information
kevinjwalls committed Sep 12, 2024
1 parent 315abdf commit 3c40afa
Show file tree
Hide file tree
Showing 22 changed files with 263 additions and 1,993 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -39,37 +39,9 @@
*
* @since 1.5
*/
@SuppressWarnings("serial") // serialVersionUID is not constant
class ClassAttributeValueExp extends AttributeValueExp {

// Serialization compatibility stuff:
// Two serial forms are supported in this class. The selected form depends
// on system property "jmx.serial.form":
// - "1.0" for JMX 1.0
// - any other value for JMX 1.1 and higher
//
// Serial version for old serial form
private static final long oldSerialVersionUID = -2212731951078526753L;
//
// Serial version for new serial form
private static final long newSerialVersionUID = -1081892073854801359L;

private static final long serialVersionUID;
static {
boolean compat = false;
try {
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
@SuppressWarnings("removal")
String form = AccessController.doPrivileged(act);
compat = (form != null && form.equals("1.0"));
} catch (Exception e) {
// OK: exception means no compat with 1.0, too bad
}
if (compat)
serialVersionUID = oldSerialVersionUID;
else
serialVersionUID = newSerialVersionUID;
}
private static final long serialVersionUID = -1081892073854801359L;

/**
* @serial The name of the attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,33 +40,9 @@
*
* @since 1.5
*/
@SuppressWarnings("serial") // serialVersionUID not constant
public class MBeanAttributeInfo extends MBeanFeatureInfo implements Cloneable {

/* Serial version */
private static final long serialVersionUID;
static {
/* For complicated reasons, the serialVersionUID changed
between JMX 1.0 and JMX 1.1, even though JMX 1.1 did not
have compatibility code for this class. So the
serialization produced by this class with JMX 1.2 and
jmx.serial.form=1.0 is not the same as that produced by
this class with JMX 1.1 and jmx.serial.form=1.0. However,
the serialization without that property is the same, and
that is the only form required by JMX 1.2.
*/
long uid = 8644704819898565848L;
try {
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
@SuppressWarnings("removal")
String form = AccessController.doPrivileged(act);
if ("1.0".equals(form))
uid = 7043855487133450673L;
} catch (Exception e) {
// OK: exception means no compat with 1.0, too bad
}
serialVersionUID = uid;
}
private static final long serialVersionUID = 8644704819898565848L;

static final MBeanAttributeInfo[] NO_ATTRIBUTES =
new MBeanAttributeInfo[0];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -53,46 +53,9 @@
*
* @since 1.5
*/
@SuppressWarnings("serial") // serialVersionUID is not constant
public class Notification extends EventObject {

// Serialization compatibility stuff:
// Two serial forms are supported in this class. The selected form depends
// on system property "jmx.serial.form":
// - "1.0" for JMX 1.0
// - any other value for JMX 1.1 and higher
//
// Serial version for old serial form
private static final long oldSerialVersionUID = 1716977971058914352L;
//
// Serial version for new serial form
private static final long newSerialVersionUID = -7516092053498031989L;
//
// Serializable fields in old serial form
private static final ObjectStreamField[] oldSerialPersistentFields =
{
new ObjectStreamField("message", String.class),
new ObjectStreamField("sequenceNumber", Long.TYPE),
new ObjectStreamField("source", Object.class),
new ObjectStreamField("sourceObjectName", ObjectName.class),
new ObjectStreamField("timeStamp", Long.TYPE),
new ObjectStreamField("type", String.class),
new ObjectStreamField("userData", Object.class)
};
//
// Serializable fields in new serial form
private static final ObjectStreamField[] newSerialPersistentFields =
{
new ObjectStreamField("message", String.class),
new ObjectStreamField("sequenceNumber", Long.TYPE),
new ObjectStreamField("source", Object.class),
new ObjectStreamField("timeStamp", Long.TYPE),
new ObjectStreamField("type", String.class),
new ObjectStreamField("userData", Object.class)
};
//
// Actual serial version and serial form
private static final long serialVersionUID;
private static final long serialVersionUID = -7516092053498031989L;
/**
* @serialField type String The notification type.
* A string expressed in a dot notation similar to Java properties.
Expand All @@ -108,28 +71,15 @@ public class Notification extends EventObject {
* @serialField message String The notification message.
* @serialField source Object The object on which the notification initially occurred.
*/
private static final ObjectStreamField[] serialPersistentFields;
private static boolean compat = false;
static {
try {
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
@SuppressWarnings("removal")
String form = AccessController.doPrivileged(act);
compat = (form != null && form.equals("1.0"));
} catch (Exception e) {
// OK: exception means no compat with 1.0, too bad
}
if (compat) {
serialPersistentFields = oldSerialPersistentFields;
serialVersionUID = oldSerialVersionUID;
} else {
serialPersistentFields = newSerialPersistentFields;
serialVersionUID = newSerialVersionUID;
}
}
//
// END Serialization compatibility stuff

private static final ObjectStreamField[] serialPersistentFields =
{
new ObjectStreamField("message", String.class),
new ObjectStreamField("sequenceNumber", Long.TYPE),
new ObjectStreamField("source", Object.class),
new ObjectStreamField("timeStamp", Long.TYPE),
new ObjectStreamField("type", String.class),
new ObjectStreamField("userData", Object.class)
};
/**
* @serial The notification type.
* A string expressed in a dot notation similar to Java properties.
Expand Down Expand Up @@ -378,21 +328,6 @@ private void readObject(ObjectInputStream in)
*/
private void writeObject(ObjectOutputStream out)
throws IOException {
if (compat) {
// Serializes this instance in the old serial form
//
ObjectOutputStream.PutField fields = out.putFields();
fields.put("type", type);
fields.put("sequenceNumber", sequenceNumber);
fields.put("timeStamp", timeStamp);
fields.put("userData", userData);
fields.put("message", message);
fields.put("source", source);
out.writeFields();
} else {
// Serializes this instance in the new serial form
//
out.defaultWriteObject();
}
out.defaultWriteObject();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -45,68 +45,19 @@
*
* @since 1.5
*/
@SuppressWarnings("serial") // serialVersionUID not constant
class NumericValueExp extends QueryEval implements ValueExp {

// Serialization compatibility stuff:
// Two serial forms are supported in this class. The selected form depends
// on system property "jmx.serial.form":
// - "1.0" for JMX 1.0
// - any other value for JMX 1.1 and higher
//
// Serial version for old serial form
private static final long oldSerialVersionUID = -6227876276058904000L;
//
// Serial version for new serial form
private static final long newSerialVersionUID = -4679739485102359104L;
//
// Serializable fields in old serial form
private static final ObjectStreamField[] oldSerialPersistentFields =
{
new ObjectStreamField("longVal", Long.TYPE),
new ObjectStreamField("doubleVal", Double.TYPE),
new ObjectStreamField("valIsLong", Boolean.TYPE)
};
//
// Serializable fields in new serial form
private static final ObjectStreamField[] newSerialPersistentFields =
{
new ObjectStreamField("val", Number.class)
};
//
// Actual serial version and serial form
private static final long serialVersionUID;

private static final long serialVersionUID = -4679739485102359104L;
/**
* @serialField val Number The numeric value
*
* <p>The <b>serialVersionUID</b> of this class is <code>-4679739485102359104L</code>.
*/
private static final ObjectStreamField[] serialPersistentFields;
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("val", Number.class)
};
private Number val = 0.0;

private static boolean compat = false;
static {
try {
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
@SuppressWarnings("removal")
String form = AccessController.doPrivileged(act);
compat = (form != null && form.equals("1.0"));
} catch (Exception e) {
// OK: exception means no compat with 1.0, too bad
}
if (compat) {
serialPersistentFields = oldSerialPersistentFields;
serialVersionUID = oldSerialVersionUID;
} else {
serialPersistentFields = newSerialPersistentFields;
serialVersionUID = newSerialVersionUID;
}
}
//
// END Serialization compatibility stuff


/**
* Basic constructor.
*/
Expand Down Expand Up @@ -189,44 +140,7 @@ public ValueExp apply(ObjectName name)
*/
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
if (compat)
{
// Read an object serialized in the old serial form
//
double doubleVal;
long longVal;
boolean isLong;
ObjectInputStream.GetField fields = in.readFields();
doubleVal = fields.get("doubleVal", (double)0);
if (fields.defaulted("doubleVal"))
{
throw new NullPointerException("doubleVal");
}
longVal = fields.get("longVal", (long)0);
if (fields.defaulted("longVal"))
{
throw new NullPointerException("longVal");
}
isLong = fields.get("valIsLong", false);
if (fields.defaulted("valIsLong"))
{
throw new NullPointerException("valIsLong");
}
if (isLong)
{
this.val = longVal;
}
else
{
this.val = doubleVal;
}
}
else
{
// Read an object serialized in the new serial form
//
in.defaultReadObject();
}
in.defaultReadObject();
}


Expand All @@ -235,22 +149,7 @@ private void readObject(ObjectInputStream in)
*/
private void writeObject(ObjectOutputStream out)
throws IOException {
if (compat)
{
// Serializes this instance in the old serial form
//
ObjectOutputStream.PutField fields = out.putFields();
fields.put("doubleVal", doubleValue());
fields.put("longVal", longValue());
fields.put("valIsLong", isLong());
out.writeFields();
}
else
{
// Serializes this instance in the new serial form
//
out.defaultWriteObject();
}
out.defaultWriteObject();
}

@Deprecated
Expand Down
Loading

0 comments on commit 3c40afa

Please sign in to comment.