8347433: Deprecate XML interchange in java.management/javax/management/modelmbean/DescriptorSupport for removal

Reviewed-by: sspitsyn, dfuchs
This commit is contained in:
Kevin Walls 2025-03-07 13:56:23 +00:00
parent 155697fc0e
commit 54fe643e78
3 changed files with 26 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2025, 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
@ -201,12 +201,16 @@ public class DescriptorSupport
* @exception XMLParseException XML parsing problem while parsing
* the input String
* @exception MBeanException Wraps a distributed communication Exception.
* @deprecated This constructor exists for historical reasons. If
* reading from XML is required, it should be implemented externally.
*/
/* At some stage we should rewrite this code to be cleverer. Using
a StringTokenizer as we do means, first, that we accept a lot of
bogus strings without noticing they are bogus, and second, that we
split the string being parsed at characters like > even if they
occur in the middle of a field value. */
@Deprecated(since="25", forRemoval=true)
@SuppressWarnings("removal")
public DescriptorSupport(String inStr)
throws MBeanException, RuntimeOperationsException,
XMLParseException {
@ -230,6 +234,7 @@ public class DescriptorSupport
if (!lowerInStr.startsWith("<descriptor>")
|| !lowerInStr.endsWith("</descriptor>")) {
throw new XMLParseException("No <descriptor>, </descriptor> pair");
// XMLParseException is deprecated for removal.
}
// parse xmlstring into structures
@ -284,11 +289,13 @@ public class DescriptorSupport
final String msg =
"Expected `name' or `value', got `" + tok + "'";
throw new XMLParseException(msg);
// XMLParseException is deprecated for removal.
}
} else { // xml parse exception
final String msg =
"Expected `keyword=value', got `" + tok + "'";
throw new XMLParseException(msg);
// XMLParseException is deprecated for removal.
}
}
} // while tokens
@ -967,7 +974,10 @@ public class DescriptorSupport
* field Names or field Values. If the XML formatted string
* construction fails for any reason, this exception will be
* thrown.
* @deprecated This method exists for historical reasons. If
* writing to XML is required, it should be implemented externally.
*/
@Deprecated(since="25", forRemoval=true)
public synchronized String toXMLString() {
final StringBuilder buf = new StringBuilder("<Descriptor>");
Set<Map.Entry<String, Object>> returnedSet = descriptorMap.entrySet();
@ -1057,9 +1067,12 @@ public class DescriptorSupport
return buf.toString();
}
@SuppressWarnings("removal")
private static String unquote(String s) throws XMLParseException {
if (!s.startsWith("\"") || !s.endsWith("\""))
if (!s.startsWith("\"") || !s.endsWith("\"")) {
throw new XMLParseException("Value must be quoted: <" + s + ">");
// XMLParseException is deprecated for removal.
}
final StringBuilder buf = new StringBuilder();
final int len = s.length() - 1;
for (int i = 1; i < len; i++) {
@ -1120,6 +1133,7 @@ public class DescriptorSupport
* - some other string, in which case the result is that string,
* without the parentheses.
*/
@SuppressWarnings("removal")
private static Object parseQuotedFieldValue(String s)
throws XMLParseException {
s = unquote(s);
@ -1142,8 +1156,8 @@ public class DescriptorSupport
Class.forName(className, false, contextClassLoader);
constr = c.getConstructor(new Class<?>[] {String.class});
} catch (Exception e) {
throw new XMLParseException(e,
"Cannot parse value: <" + s + ">");
throw new XMLParseException(e, "Cannot parse value: <" + s + ">");
// XMLParseException is deprecated for removal.
}
final String arg = s.substring(slash + 1, s.length() - 1);
try {
@ -1153,6 +1167,7 @@ public class DescriptorSupport
"Cannot construct instance of " + className +
" with arg: <" + s + ">";
throw new XMLParseException(e, msg);
// XMLParseException is deprecated for removal.
}
}

View File

@ -91,8 +91,7 @@ import sun.reflect.misc.MethodUtil;
* from MBeans, connectors/adaptors like other MBeans. Through the
* Descriptors, values and methods in the managed application can be
* defined and mapped to attributes and operations of the ModelMBean.
* This mapping can be defined in an XML formatted file or dynamically and
* programmatically at runtime.
* This mapping can be defined dynamically and programmatically at runtime.
* <P>
* Every RequiredModelMBean which is instantiated in the MBeanServer
* becomes manageable:<br>
@ -129,7 +128,6 @@ public class RequiredModelMBean
* and operations will be executed */
private Object managedResource = null;
/* records the registering in MBeanServer */
private boolean registered = false;
private transient MBeanServer server = null;
@ -367,7 +365,7 @@ public class RequiredModelMBean
throw new MBeanException(x, x.getMessage());
}
/**
/**
* <p>Captures the current state of this MBean instance and writes
* it out to the persistent store. The state stored could include
* attribute and operation values.</p>
@ -651,7 +649,6 @@ public class RequiredModelMBean
retStr.append("\nCLASSNAME: \t").append(info.getClassName());
retStr.append("\nDESCRIPTION: \t").append(info.getDescription());
try {
retStr.append("\nMBEAN DESCRIPTOR: \t").append(info.getMBeanDescriptor());
} catch (Exception e) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2025, 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
@ -44,8 +44,12 @@ import java.io.ObjectStreamField;
*
* <p>The <b>serialVersionUID</b> of this class is <code>3176664577895105181L</code>.
*
* @deprecated This class exists only to support XML parsing implemented privately in this module,
* in DescriptorSupport. That feature is deprecated for removal.
*
* @since 1.5
*/
@Deprecated(since="25", forRemoval=true)
public class XMLParseException
extends Exception
{