Skip to content

Commit 3c40afa

Browse files
committed
8334165: Remove serialVersionUID compatibility logic from JMX
Reviewed-by: dfuchs
1 parent 315abdf commit 3c40afa

22 files changed

+263
-1993
lines changed

src/java.management/share/classes/javax/management/ClassAttributeValueExp.java

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,37 +39,9 @@
3939
*
4040
* @since 1.5
4141
*/
42-
@SuppressWarnings("serial") // serialVersionUID is not constant
4342
class ClassAttributeValueExp extends AttributeValueExp {
4443

45-
// Serialization compatibility stuff:
46-
// Two serial forms are supported in this class. The selected form depends
47-
// on system property "jmx.serial.form":
48-
// - "1.0" for JMX 1.0
49-
// - any other value for JMX 1.1 and higher
50-
//
51-
// Serial version for old serial form
52-
private static final long oldSerialVersionUID = -2212731951078526753L;
53-
//
54-
// Serial version for new serial form
55-
private static final long newSerialVersionUID = -1081892073854801359L;
56-
57-
private static final long serialVersionUID;
58-
static {
59-
boolean compat = false;
60-
try {
61-
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
62-
@SuppressWarnings("removal")
63-
String form = AccessController.doPrivileged(act);
64-
compat = (form != null && form.equals("1.0"));
65-
} catch (Exception e) {
66-
// OK: exception means no compat with 1.0, too bad
67-
}
68-
if (compat)
69-
serialVersionUID = oldSerialVersionUID;
70-
else
71-
serialVersionUID = newSerialVersionUID;
72-
}
44+
private static final long serialVersionUID = -1081892073854801359L;
7345

7446
/**
7547
* @serial The name of the attribute

src/java.management/share/classes/javax/management/MBeanAttributeInfo.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,33 +40,9 @@
4040
*
4141
* @since 1.5
4242
*/
43-
@SuppressWarnings("serial") // serialVersionUID not constant
4443
public class MBeanAttributeInfo extends MBeanFeatureInfo implements Cloneable {
4544

46-
/* Serial version */
47-
private static final long serialVersionUID;
48-
static {
49-
/* For complicated reasons, the serialVersionUID changed
50-
between JMX 1.0 and JMX 1.1, even though JMX 1.1 did not
51-
have compatibility code for this class. So the
52-
serialization produced by this class with JMX 1.2 and
53-
jmx.serial.form=1.0 is not the same as that produced by
54-
this class with JMX 1.1 and jmx.serial.form=1.0. However,
55-
the serialization without that property is the same, and
56-
that is the only form required by JMX 1.2.
57-
*/
58-
long uid = 8644704819898565848L;
59-
try {
60-
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
61-
@SuppressWarnings("removal")
62-
String form = AccessController.doPrivileged(act);
63-
if ("1.0".equals(form))
64-
uid = 7043855487133450673L;
65-
} catch (Exception e) {
66-
// OK: exception means no compat with 1.0, too bad
67-
}
68-
serialVersionUID = uid;
69-
}
45+
private static final long serialVersionUID = 8644704819898565848L;
7046

7147
static final MBeanAttributeInfo[] NO_ATTRIBUTES =
7248
new MBeanAttributeInfo[0];

src/java.management/share/classes/javax/management/Notification.java

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -53,46 +53,9 @@
5353
*
5454
* @since 1.5
5555
*/
56-
@SuppressWarnings("serial") // serialVersionUID is not constant
5756
public class Notification extends EventObject {
5857

59-
// Serialization compatibility stuff:
60-
// Two serial forms are supported in this class. The selected form depends
61-
// on system property "jmx.serial.form":
62-
// - "1.0" for JMX 1.0
63-
// - any other value for JMX 1.1 and higher
64-
//
65-
// Serial version for old serial form
66-
private static final long oldSerialVersionUID = 1716977971058914352L;
67-
//
68-
// Serial version for new serial form
69-
private static final long newSerialVersionUID = -7516092053498031989L;
70-
//
71-
// Serializable fields in old serial form
72-
private static final ObjectStreamField[] oldSerialPersistentFields =
73-
{
74-
new ObjectStreamField("message", String.class),
75-
new ObjectStreamField("sequenceNumber", Long.TYPE),
76-
new ObjectStreamField("source", Object.class),
77-
new ObjectStreamField("sourceObjectName", ObjectName.class),
78-
new ObjectStreamField("timeStamp", Long.TYPE),
79-
new ObjectStreamField("type", String.class),
80-
new ObjectStreamField("userData", Object.class)
81-
};
82-
//
83-
// Serializable fields in new serial form
84-
private static final ObjectStreamField[] newSerialPersistentFields =
85-
{
86-
new ObjectStreamField("message", String.class),
87-
new ObjectStreamField("sequenceNumber", Long.TYPE),
88-
new ObjectStreamField("source", Object.class),
89-
new ObjectStreamField("timeStamp", Long.TYPE),
90-
new ObjectStreamField("type", String.class),
91-
new ObjectStreamField("userData", Object.class)
92-
};
93-
//
94-
// Actual serial version and serial form
95-
private static final long serialVersionUID;
58+
private static final long serialVersionUID = -7516092053498031989L;
9659
/**
9760
* @serialField type String The notification type.
9861
* A string expressed in a dot notation similar to Java properties.
@@ -108,28 +71,15 @@ public class Notification extends EventObject {
10871
* @serialField message String The notification message.
10972
* @serialField source Object The object on which the notification initially occurred.
11073
*/
111-
private static final ObjectStreamField[] serialPersistentFields;
112-
private static boolean compat = false;
113-
static {
114-
try {
115-
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
116-
@SuppressWarnings("removal")
117-
String form = AccessController.doPrivileged(act);
118-
compat = (form != null && form.equals("1.0"));
119-
} catch (Exception e) {
120-
// OK: exception means no compat with 1.0, too bad
121-
}
122-
if (compat) {
123-
serialPersistentFields = oldSerialPersistentFields;
124-
serialVersionUID = oldSerialVersionUID;
125-
} else {
126-
serialPersistentFields = newSerialPersistentFields;
127-
serialVersionUID = newSerialVersionUID;
128-
}
129-
}
130-
//
131-
// END Serialization compatibility stuff
132-
74+
private static final ObjectStreamField[] serialPersistentFields =
75+
{
76+
new ObjectStreamField("message", String.class),
77+
new ObjectStreamField("sequenceNumber", Long.TYPE),
78+
new ObjectStreamField("source", Object.class),
79+
new ObjectStreamField("timeStamp", Long.TYPE),
80+
new ObjectStreamField("type", String.class),
81+
new ObjectStreamField("userData", Object.class)
82+
};
13383
/**
13484
* @serial The notification type.
13585
* A string expressed in a dot notation similar to Java properties.
@@ -378,21 +328,6 @@ private void readObject(ObjectInputStream in)
378328
*/
379329
private void writeObject(ObjectOutputStream out)
380330
throws IOException {
381-
if (compat) {
382-
// Serializes this instance in the old serial form
383-
//
384-
ObjectOutputStream.PutField fields = out.putFields();
385-
fields.put("type", type);
386-
fields.put("sequenceNumber", sequenceNumber);
387-
fields.put("timeStamp", timeStamp);
388-
fields.put("userData", userData);
389-
fields.put("message", message);
390-
fields.put("source", source);
391-
out.writeFields();
392-
} else {
393-
// Serializes this instance in the new serial form
394-
//
395-
out.defaultWriteObject();
396-
}
331+
out.defaultWriteObject();
397332
}
398333
}

src/java.management/share/classes/javax/management/NumericValueExp.java

Lines changed: 7 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -45,68 +45,19 @@
4545
*
4646
* @since 1.5
4747
*/
48-
@SuppressWarnings("serial") // serialVersionUID not constant
4948
class NumericValueExp extends QueryEval implements ValueExp {
5049

51-
// Serialization compatibility stuff:
52-
// Two serial forms are supported in this class. The selected form depends
53-
// on system property "jmx.serial.form":
54-
// - "1.0" for JMX 1.0
55-
// - any other value for JMX 1.1 and higher
56-
//
57-
// Serial version for old serial form
58-
private static final long oldSerialVersionUID = -6227876276058904000L;
59-
//
60-
// Serial version for new serial form
61-
private static final long newSerialVersionUID = -4679739485102359104L;
62-
//
63-
// Serializable fields in old serial form
64-
private static final ObjectStreamField[] oldSerialPersistentFields =
65-
{
66-
new ObjectStreamField("longVal", Long.TYPE),
67-
new ObjectStreamField("doubleVal", Double.TYPE),
68-
new ObjectStreamField("valIsLong", Boolean.TYPE)
69-
};
70-
//
71-
// Serializable fields in new serial form
72-
private static final ObjectStreamField[] newSerialPersistentFields =
73-
{
74-
new ObjectStreamField("val", Number.class)
75-
};
76-
//
77-
// Actual serial version and serial form
78-
private static final long serialVersionUID;
79-
50+
private static final long serialVersionUID = -4679739485102359104L;
8051
/**
8152
* @serialField val Number The numeric value
8253
*
8354
* <p>The <b>serialVersionUID</b> of this class is <code>-4679739485102359104L</code>.
8455
*/
85-
private static final ObjectStreamField[] serialPersistentFields;
56+
private static final ObjectStreamField[] serialPersistentFields = {
57+
new ObjectStreamField("val", Number.class)
58+
};
8659
private Number val = 0.0;
8760

88-
private static boolean compat = false;
89-
static {
90-
try {
91-
GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
92-
@SuppressWarnings("removal")
93-
String form = AccessController.doPrivileged(act);
94-
compat = (form != null && form.equals("1.0"));
95-
} catch (Exception e) {
96-
// OK: exception means no compat with 1.0, too bad
97-
}
98-
if (compat) {
99-
serialPersistentFields = oldSerialPersistentFields;
100-
serialVersionUID = oldSerialVersionUID;
101-
} else {
102-
serialPersistentFields = newSerialPersistentFields;
103-
serialVersionUID = newSerialVersionUID;
104-
}
105-
}
106-
//
107-
// END Serialization compatibility stuff
108-
109-
11061
/**
11162
* Basic constructor.
11263
*/
@@ -189,44 +140,7 @@ public ValueExp apply(ObjectName name)
189140
*/
190141
private void readObject(ObjectInputStream in)
191142
throws IOException, ClassNotFoundException {
192-
if (compat)
193-
{
194-
// Read an object serialized in the old serial form
195-
//
196-
double doubleVal;
197-
long longVal;
198-
boolean isLong;
199-
ObjectInputStream.GetField fields = in.readFields();
200-
doubleVal = fields.get("doubleVal", (double)0);
201-
if (fields.defaulted("doubleVal"))
202-
{
203-
throw new NullPointerException("doubleVal");
204-
}
205-
longVal = fields.get("longVal", (long)0);
206-
if (fields.defaulted("longVal"))
207-
{
208-
throw new NullPointerException("longVal");
209-
}
210-
isLong = fields.get("valIsLong", false);
211-
if (fields.defaulted("valIsLong"))
212-
{
213-
throw new NullPointerException("valIsLong");
214-
}
215-
if (isLong)
216-
{
217-
this.val = longVal;
218-
}
219-
else
220-
{
221-
this.val = doubleVal;
222-
}
223-
}
224-
else
225-
{
226-
// Read an object serialized in the new serial form
227-
//
228-
in.defaultReadObject();
229-
}
143+
in.defaultReadObject();
230144
}
231145

232146

@@ -235,22 +149,7 @@ private void readObject(ObjectInputStream in)
235149
*/
236150
private void writeObject(ObjectOutputStream out)
237151
throws IOException {
238-
if (compat)
239-
{
240-
// Serializes this instance in the old serial form
241-
//
242-
ObjectOutputStream.PutField fields = out.putFields();
243-
fields.put("doubleVal", doubleValue());
244-
fields.put("longVal", longValue());
245-
fields.put("valIsLong", isLong());
246-
out.writeFields();
247-
}
248-
else
249-
{
250-
// Serializes this instance in the new serial form
251-
//
252-
out.defaultWriteObject();
253-
}
152+
out.defaultWriteObject();
254153
}
255154

256155
@Deprecated

0 commit comments

Comments
 (0)