diff --git a/src/java.management/share/classes/javax/management/ClassAttributeValueExp.java b/src/java.management/share/classes/javax/management/ClassAttributeValueExp.java index 06c488f90fac7..f7c40691e39b5 100644 --- a/src/java.management/share/classes/javax/management/ClassAttributeValueExp.java +++ b/src/java.management/share/classes/javax/management/ClassAttributeValueExp.java @@ -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 @@ -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 diff --git a/src/java.management/share/classes/javax/management/MBeanAttributeInfo.java b/src/java.management/share/classes/javax/management/MBeanAttributeInfo.java index 6d31becbb7317..6551e9ba81bfa 100644 --- a/src/java.management/share/classes/javax/management/MBeanAttributeInfo.java +++ b/src/java.management/share/classes/javax/management/MBeanAttributeInfo.java @@ -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 @@ -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]; diff --git a/src/java.management/share/classes/javax/management/Notification.java b/src/java.management/share/classes/javax/management/Notification.java index 9455264fa04eb..80cf4b464d268 100644 --- a/src/java.management/share/classes/javax/management/Notification.java +++ b/src/java.management/share/classes/javax/management/Notification.java @@ -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 @@ -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. @@ -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. @@ -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(); } } diff --git a/src/java.management/share/classes/javax/management/NumericValueExp.java b/src/java.management/share/classes/javax/management/NumericValueExp.java index 959375a2f500d..bae84019d2e31 100644 --- a/src/java.management/share/classes/javax/management/NumericValueExp.java +++ b/src/java.management/share/classes/javax/management/NumericValueExp.java @@ -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 @@ -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 * *

The serialVersionUID of this class is -4679739485102359104L. */ - 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. */ @@ -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(); } @@ -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 diff --git a/src/java.management/share/classes/javax/management/ObjectName.java b/src/java.management/share/classes/javax/management/ObjectName.java index 00d5cc6930d60..f20750c9d8a84 100644 --- a/src/java.management/share/classes/javax/management/ObjectName.java +++ b/src/java.management/share/classes/javax/management/ObjectName.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2022, 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 @@ -222,7 +222,6 @@ * @implNote The maximum allowed length of the domain name in this implementation * is {@code Integer.MAX_VALUE/4} */ -@SuppressWarnings("serial") // don't complain serialVersionUID not constant public class ObjectName implements Comparable, QueryExp { private static final int DOMAIN_PATTERN = 0x8000_0000; private static final int PROPLIST_PATTERN = 0x4000_0000; @@ -294,57 +293,7 @@ private static class PatternProperty extends Property { // Private fields ----------------------------------------> - // 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 = -5467795090068647408L; - // - // Serial version for new serial form - private static final long newSerialVersionUID = 1081892073854801359L; - // - // Serializable fields in old serial form - private static final ObjectStreamField[] oldSerialPersistentFields = - { - new ObjectStreamField("domain", String.class), - new ObjectStreamField("propertyList", Hashtable.class), - new ObjectStreamField("propertyListString", String.class), - new ObjectStreamField("canonicalName", String.class), - new ObjectStreamField("pattern", Boolean.TYPE), - new ObjectStreamField("propertyPattern", Boolean.TYPE) - }; - // - // Serializable fields in new serial form - private static final ObjectStreamField[] newSerialPersistentFields = { }; - // - // Actual serial version and serial form - private static final long serialVersionUID; - 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; - } - } - - // - // Serialization compatibility stuff <============================== + private static final long serialVersionUID = 1081892073854801359L; // Class private fields -----------------------------------> @@ -1088,90 +1037,32 @@ private void setDomainLength(int length) throws MalformedObjectNameException { /** * Deserializes an {@link ObjectName} from an {@link ObjectInputStream}. - * @serialData