8318707: Remove the Java Management Extension (JMX) Management Applet (m-let) feature

Reviewed-by: sspitsyn, dfuchs
This commit is contained in:
Kevin Walls 2024-01-15 11:12:38 +00:00
parent cd0fe37741
commit 8c238eddce
41 changed files with 139 additions and 3490 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2017, 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
@ -44,24 +44,14 @@ public class JmxProperties {
//------------------------
/**
* References the property that specifies the directory where
* the native libraries will be stored before the MLet Service
* loads them into memory.
* References the property that optionally specifies the class name
* of an alternative MBeanServerBuilder.
* <p>
* Property Name: <B>jmx.mlet.library.dir</B>
* Property Name: <B>javax.management.builder.initial</B>
*/
public static final String JMX_INITIAL_BUILDER =
"javax.management.builder.initial";
/**
* References the property that specifies the directory where
* the native libraries will be stored before the MLet Service
* loads them into memory.
* <p>
* Property Name: <B>jmx.mlet.library.dir</B>
*/
public static final String MLET_LIB_DIR = "jmx.mlet.library.dir";
/**
* References the property that specifies the full name of the JMX
* specification implemented by this product.
@ -122,18 +112,6 @@ public class JmxProperties {
public static final Logger MBEANSERVER_LOGGER =
System.getLogger(MBEANSERVER_LOGGER_NAME);
/**
* Logger name for MLet service information.
*/
public static final String MLET_LOGGER_NAME =
"javax.management.mlet";
/**
* Logger for MLet service information.
*/
public static final Logger MLET_LOGGER =
System.getLogger(MLET_LOGGER_NAME);
/**
* Logger name for Monitor information.
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2008, 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
@ -44,14 +44,6 @@ public class ServiceName {
public static final String DELEGATE =
"JMImplementation:type=MBeanServerDelegate" ;
/**
* The default key properties for registering the class loader of the
* MLet service.
* <BR>
* The value is <CODE>type=MLet</CODE>.
*/
public static final String MLET = "type=MLet";
/**
* The default domain.
* <BR>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2002, 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
@ -206,18 +206,6 @@ final class ClassLoaderRepositorySupport
if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) {
MBEANSERVER_LOGGER.log(Level.TRACE, "Trying loader = " + cl);
}
/* We used to have a special case for "instanceof
MLet" here, where we invoked the method
loadClass(className, null) to prevent infinite
recursion. But the rule whereby the MLet only
consults loaders that precede it in the CLR (via
loadClassBefore) means that the recursion can't
happen, and the test here caused some legitimate
classloading to fail. For example, if you have
dependencies C->D->E with loaders {E D C} in the
CLR in that order, you would expect to be able to
load C. The problem is that while resolving D, CLR
delegation is disabled, so it can't find E. */
return Class.forName(className, false, cl);
} catch (ClassNotFoundException e) {
// OK: continue with next class

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -75,12 +75,11 @@ import javax.management.remote.MBeanServerForwarder;
* inappropriate.</p>
*
* <p>If there is no SecurityManager, then the access controller will refuse
* to create an MBean that is a ClassLoader, which includes MLets, or to
* execute the method addURL on an MBean that is an MLet. This prevents
* to create an MBean that is a ClassLoader. This prevents
* people from opening security holes unintentionally. Otherwise, it
* would not be obvious that granting write access grants the ability to
* download and execute arbitrary code in the target MBean server. Advanced
* users who do want the ability to use MLets are presumably advanced enough
* users who do want an MBean which is a ClassLoader are presumably advanced enough
* to handle policy files and security managers.</p>
*/
public abstract class MBeanServerAccessController
@ -468,7 +467,6 @@ public abstract class MBeanServerAccessController
MBeanException,
ReflectionException {
checkWrite();
checkMLetMethods(name, operationName);
return getMBeanServer().invoke(name, operationName, params, signature);
}
@ -620,49 +618,6 @@ public abstract class MBeanServerAccessController
"manager is installed.");
}
private void checkMLetMethods(ObjectName name, String operation)
throws InstanceNotFoundException {
// Check if security manager installed
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
return;
}
// Check for addURL and getMBeansFromURL methods
if (!operation.equals("addURL") &&
!operation.equals("getMBeansFromURL")) {
return;
}
// Check if MBean is instance of MLet
if (!getMBeanServer().isInstanceOf(name,
"javax.management.loading.MLet")) {
return;
}
// Throw security exception
if (operation.equals("addURL")) { // addURL
throw new SecurityException("Access denied! MLet method addURL " +
"cannot be invoked unless a security manager is installed.");
} else { // getMBeansFromURL
// Whether or not calling getMBeansFromURL is allowed is controlled
// by the value of the "jmx.remote.x.mlet.allow.getMBeansFromURL"
// system property. If the value of this property is true, calling
// the MLet's getMBeansFromURL method is allowed. The default value
// for this property is false.
final String propName = "jmx.remote.x.mlet.allow.getMBeansFromURL";
GetPropertyAction propAction = new GetPropertyAction(propName);
@SuppressWarnings("removal")
String propValue = AccessController.doPrivileged(propAction);
boolean allowGetMBeansFromURL = "true".equalsIgnoreCase(propValue);
if (!allowGetMBeansFromURL) {
throw new SecurityException("Access denied! MLet method " +
"getMBeansFromURL cannot be invoked unless a " +
"security manager is installed or the system property " +
"-Djmx.remote.x.mlet.allow.getMBeansFromURL=true " +
"is specified.");
}
}
}
//------------------
// PRIVATE VARIABLES
//------------------

View File

@ -1,245 +0,0 @@
/*
* Copyright (c) 1999, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.management.loading;
// java import
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* This class represents the contents of the <CODE>MLET</CODE> tag.
* It can be consulted by a subclass of {@link MLet} that overrides
* the {@link MLet#check MLet.check} method.
*
* @deprecated This API is part of Management Applets (m-lets), which is a legacy feature that allows loading
* of remote MBeans. This feature is not usable without a Security Manager, which is deprecated and subject to
* removal in a future release. Consequently, this API is also deprecated and subject to removal. There is no replacement.
*
* @since 1.6
*/
@Deprecated(since="20", forRemoval=true)
public class MLetContent {
/**
* A map of the attributes of the <CODE>MLET</CODE> tag
* and their values.
*/
private Map<String,String> attributes;
/**
* An ordered list of the TYPE attributes that appeared in nested
* &lt;PARAM&gt; tags.
*/
private List<String> types;
/**
* An ordered list of the VALUE attributes that appeared in nested
* &lt;PARAM&gt; tags.
*/
private List<String> values;
/**
* The MLet text file's base URL.
*/
private URL documentURL;
/**
* The base URL.
*/
private URL baseURL;
/**
* Creates an <CODE>MLet</CODE> instance initialized with attributes read
* from an <CODE>MLET</CODE> tag in an MLet text file.
*
* @param url The URL of the MLet text file containing the
* <CODE>MLET</CODE> tag.
* @param attributes A map of the attributes of the <CODE>MLET</CODE> tag.
* The keys in this map are the attribute names in lowercase, for
* example <code>codebase</code>. The values are the associated attribute
* values.
* @param types A list of the TYPE attributes that appeared in nested
* &lt;PARAM&gt; tags.
* @param values A list of the VALUE attributes that appeared in nested
* &lt;PARAM&gt; tags.
*/
public MLetContent(URL url, Map<String,String> attributes,
List<String> types, List<String> values) {
this.documentURL = url;
this.attributes = Collections.unmodifiableMap(attributes);
this.types = Collections.unmodifiableList(types);
this.values = Collections.unmodifiableList(values);
// Initialize baseURL
//
String att = getParameter("codebase");
if (att != null) {
if (!att.endsWith("/")) {
att += "/";
}
try {
@SuppressWarnings("deprecation")
var _unused = baseURL = new URL(documentURL, att);
} catch (MalformedURLException e) {
// OK : Move to next block as baseURL could not be initialized.
}
}
if (baseURL == null) {
String file = documentURL.getFile();
int i = file.lastIndexOf('/');
if (i >= 0 && i < file.length() - 1) {
try {
@SuppressWarnings("deprecation")
var _unused = baseURL = new URL(documentURL, file.substring(0, i + 1));
} catch (MalformedURLException e) {
// OK : Move to next block as baseURL could not be initialized.
}
}
}
if (baseURL == null)
baseURL = documentURL;
}
// GETTERS AND SETTERS
//--------------------
/**
* Gets the attributes of the <CODE>MLET</CODE> tag. The keys in
* the returned map are the attribute names in lowercase, for
* example <code>codebase</code>. The values are the associated
* attribute values.
* @return A map of the attributes of the <CODE>MLET</CODE> tag
* and their values.
*/
public Map<String,String> getAttributes() {
return attributes;
}
/**
* Gets the MLet text file's base URL.
* @return The MLet text file's base URL.
*/
public URL getDocumentBase() {
return documentURL;
}
/**
* Gets the code base URL.
* @return The code base URL.
*/
public URL getCodeBase() {
return baseURL;
}
/**
* Gets the list of <CODE>.jar</CODE> files specified by the <CODE>ARCHIVE</CODE>
* attribute of the <CODE>MLET</CODE> tag.
* @return A comma-separated list of <CODE>.jar</CODE> file names.
*/
public String getJarFiles() {
return getParameter("archive");
}
/**
* Gets the value of the <CODE>CODE</CODE>
* attribute of the <CODE>MLET</CODE> tag.
* @return The value of the <CODE>CODE</CODE>
* attribute of the <CODE>MLET</CODE> tag.
*/
public String getCode() {
return getParameter("code");
}
/**
* Gets the value of the <CODE>OBJECT</CODE>
* attribute of the <CODE>MLET</CODE> tag.
* @return The value of the <CODE>OBJECT</CODE>
* attribute of the <CODE>MLET</CODE> tag.
*/
public String getSerializedObject() {
return getParameter("object");
}
/**
* Gets the value of the <CODE>NAME</CODE>
* attribute of the <CODE>MLET</CODE> tag.
* @return The value of the <CODE>NAME</CODE>
* attribute of the <CODE>MLET</CODE> tag.
*/
public String getName() {
return getParameter("name");
}
/**
* Gets the value of the <CODE>VERSION</CODE>
* attribute of the <CODE>MLET</CODE> tag.
* @return The value of the <CODE>VERSION</CODE>
* attribute of the <CODE>MLET</CODE> tag.
*/
public String getVersion() {
return getParameter("version");
}
/**
* Gets the list of values of the <code>TYPE</code> attribute in
* each nested &lt;PARAM&gt; tag within the <code>MLET</code>
* tag.
* @return the list of types.
*/
public List<String> getParameterTypes() {
return types;
}
/**
* Gets the list of values of the <code>VALUE</code> attribute in
* each nested &lt;PARAM&gt; tag within the <code>MLET</code>
* tag.
* @return the list of values.
*/
public List<String> getParameterValues() {
return values;
}
/**
* Gets the value of the specified
* attribute of the <CODE>MLET</CODE> tag.
*
* @param name A string representing the name of the attribute.
* @return The value of the specified
* attribute of the <CODE>MLET</CODE> tag.
*/
private String getParameter(String name) {
return attributes.get(name.toLowerCase());
}
}

View File

@ -1,190 +0,0 @@
/*
* Copyright (c) 1999, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.management.loading;
import java.net.URL;
import java.io.InputStream;
import java.io.IOException;
import java.util.Set;
import java.util.Enumeration;
import javax.management.*;
/**
* Exposes the remote management interface of the MLet
* MBean.
*
* @deprecated This API is part of Management Applets (m-lets), which is a legacy feature that allows loading
* of remote MBeans. This feature is not usable without a Security Manager, which is deprecated and subject to
* removal in a future release. Consequently, this API is also deprecated and subject to removal. There is no replacement.
*
* @since 1.5
*/
@Deprecated(since="20", forRemoval=true)
public interface MLetMBean {
/**
* Loads a text file containing MLET tags that define the MBeans
* to be added to the MBean server. The location of the text file is
* specified by a URL. The text file is read using the UTF-8
* encoding. The MBeans specified in the MLET file will be
* instantiated and registered in the MBean server.
*
* @param url The URL of the text file to be loaded as String object.
*
* @return A set containing one entry per MLET tag in the m-let
* text file loaded. Each entry specifies either the
* ObjectInstance for the created MBean, or a throwable object
* (that is, an error or an exception) if the MBean could not be
* created.
*
* @exception ServiceNotFoundException One of the following errors
* has occurred: The m-let text file does not contain an MLET tag,
* the m-let text file is not found, a mandatory attribute of the
* MLET tag is not specified, the value of url is malformed.
*/
public Set<Object> getMBeansFromURL(String url)
throws ServiceNotFoundException;
/**
* Loads a text file containing MLET tags that define the MBeans
* to be added to the MBean server. The location of the text file is
* specified by a URL. The text file is read using the UTF-8
* encoding. The MBeans specified in the MLET file will be
* instantiated and registered in the MBean server.
*
* @param url The URL of the text file to be loaded as URL object.
*
* @return A set containing one entry per MLET tag in the m-let
* text file loaded. Each entry specifies either the
* ObjectInstance for the created MBean, or a throwable object
* (that is, an error or an exception) if the MBean could not be
* created.
*
* @exception ServiceNotFoundException One of the following errors
* has occurred: The m-let text file does not contain an MLET tag,
* the m-let text file is not found, a mandatory attribute of the
* MLET tag is not specified, the value of url is null.
*/
public Set<Object> getMBeansFromURL(URL url)
throws ServiceNotFoundException;
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
*
* @param url the URL to add.
*/
public void addURL(URL url) ;
/**
* Appends the specified URL to the list of URLs to search for classes and
* resources.
*
* @param url the URL to add.
*
* @exception ServiceNotFoundException The specified URL is malformed.
*/
public void addURL(String url) throws ServiceNotFoundException;
/**
* Returns the search path of URLs for loading classes and resources.
* This includes the original list of URLs specified to the constructor,
* along with any URLs subsequently appended by the addURL() method.
*
* @return the list of URLs.
*/
public URL[] getURLs();
/** Finds the resource with the given name.
* A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is
* independent of the location of the code.
* The name of a resource is a "/"-separated path name that identifies the resource.
*
* @param name The resource name
*
* @return An URL for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the
* resource.
*/
public URL getResource(String name);
/** Returns an input stream for reading the specified resource. The search order is described in the documentation for
* getResource(String).
*
* @param name The resource name
*
* @return An input stream for reading the resource, or null if the resource could not be found
*
*/
public InputStream getResourceAsStream(String name);
/**
* Finds all the resources with the given name. A resource is some
* data (images, audio, text, etc) that can be accessed by class
* code in a way that is independent of the location of the code.
* The name of a resource is a "/"-separated path name that
* identifies the resource.
*
* @param name The resource name.
*
* @return An enumeration of URL to the resource. If no resources
* could be found, the enumeration will be empty. Resources that
* cannot be accessed will not be in the enumeration.
*
* @exception IOException if an I/O exception occurs when
* searching for resources.
*/
public Enumeration<URL> getResources(String name) throws IOException;
/**
* Gets the current directory used by the library loader for
* storing native libraries before they are loaded into memory.
*
* @return The current directory used by the library loader.
*
* @see #setLibraryDirectory
*
* @throws UnsupportedOperationException if this implementation
* does not support storing native libraries in this way.
*/
public String getLibraryDirectory();
/**
* Sets the directory used by the library loader for storing
* native libraries before they are loaded into memory.
*
* @param libdir The directory used by the library loader.
*
* @see #getLibraryDirectory
*
* @throws UnsupportedOperationException if this implementation
* does not support storing native libraries in this way.
*/
public void setLibraryDirectory(String libdir);
}

View File

@ -1,125 +0,0 @@
/*
* Copyright (c) 1999, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.management.loading;
// java import
import java.io.*;
import java.lang.reflect.Array;
/**
* This subclass of ObjectInputStream delegates loading of classes to
* an existing MLetClassLoader.
*
* @since 1.5
*/
@Deprecated(since="20", forRemoval=true)
class MLetObjectInputStream extends ObjectInputStream {
@SuppressWarnings("removal")
private MLet loader;
/**
* Loader must be non-null;
*/
@SuppressWarnings("removal")
public MLetObjectInputStream(InputStream in, MLet loader)
throws IOException, StreamCorruptedException {
super(in);
if (loader == null) {
throw new IllegalArgumentException("Illegal null argument to MLetObjectInputStream");
}
this.loader = loader;
}
private Class<?> primitiveType(char c) {
switch(c) {
case 'B':
return Byte.TYPE;
case 'C':
return Character.TYPE;
case 'D':
return Double.TYPE;
case 'F':
return Float.TYPE;
case 'I':
return Integer.TYPE;
case 'J':
return Long.TYPE;
case 'S':
return Short.TYPE;
case 'Z':
return Boolean.TYPE;
}
return null;
}
/**
* Use the given ClassLoader rather than using the system class
*/
@Override
protected Class<?> resolveClass(ObjectStreamClass objectstreamclass)
throws IOException, ClassNotFoundException {
String s = objectstreamclass.getName();
if (s.startsWith("[")) {
int i;
for (i = 1; s.charAt(i) == '['; i++);
Class<?> class1;
if (s.charAt(i) == 'L') {
class1 = loader.loadClass(s.substring(i + 1, s.length() - 1));
} else {
if (s.length() != i + 1)
throw new ClassNotFoundException(s);
class1 = primitiveType(s.charAt(i));
}
int ai[] = new int[i];
for (int j = 0; j < i; j++)
ai[j] = 0;
return Array.newInstance(class1, ai).getClass();
} else {
return loader.loadClass(s);
}
}
/**
* Returns the ClassLoader being used
*/
public ClassLoader getClassLoader() {
return loader;
}
}

View File

@ -1,279 +0,0 @@
/*
* Copyright (c) 1999, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.management.loading;
import static com.sun.jmx.defaults.JmxProperties.MLET_LOGGER;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.lang.System.Logger.Level;
/**
* This class is used for parsing URLs.
*
* @since 1.5
*/
@Deprecated(since="20", forRemoval=true)
class MLetParser {
/*
* ------------------------------------------
* PRIVATE VARIABLES
* ------------------------------------------
*/
/**
* The current character
*/
private int c;
/**
* Tag to parse.
*/
private static String tag = "mlet";
/*
* ------------------------------------------
* CONSTRUCTORS
* ------------------------------------------
*/
/**
* Create an MLet parser object
*/
public MLetParser() {
}
/*
* ------------------------------------------
* PUBLIC METHODS
* ------------------------------------------
*/
/**
* Scan spaces.
*/
public void skipSpace(Reader in) throws IOException {
while ((c >= 0) && ((c == ' ') || (c == '\t') || (c == '\n') || (c == '\r'))) {
c = in.read();
}
}
/**
* Scan identifier
*/
public String scanIdentifier(Reader in) throws IOException {
StringBuilder buf = new StringBuilder();
while (true) {
if (((c >= 'a') && (c <= 'z')) ||
((c >= 'A') && (c <= 'Z')) ||
((c >= '0') && (c <= '9')) || (c == '_')) {
buf.append((char)c);
c = in.read();
} else {
return buf.toString();
}
}
}
/**
* Scan tag
*/
public Map<String,String> scanTag(Reader in) throws IOException {
Map<String,String> atts = new HashMap<>();
skipSpace(in);
while (c >= 0 && c != '>') {
if (c == '<')
throw new IOException("Missing '>' in tag");
String att = scanIdentifier(in);
String val = "";
skipSpace(in);
if (c == '=') {
int quote = -1;
c = in.read();
skipSpace(in);
if ((c == '\'') || (c == '\"')) {
quote = c;
c = in.read();
}
StringBuilder buf = new StringBuilder();
while ((c > 0) &&
(((quote < 0) && (c != ' ') && (c != '\t') &&
(c != '\n') && (c != '\r') && (c != '>'))
|| ((quote >= 0) && (c != quote)))) {
buf.append((char)c);
c = in.read();
}
if (c == quote) {
c = in.read();
}
skipSpace(in);
val = buf.toString();
}
atts.put(att.toLowerCase(Locale.ENGLISH), val);
skipSpace(in);
}
return atts;
}
/**
* Scan an html file for {@literal <mlet>} tags.
*/
@SuppressWarnings("removal")
public List<MLetContent> parse(URL url) throws IOException {
// Warning Messages
String requiresTypeWarning = "<arg type=... value=...> tag requires type parameter.";
String requiresValueWarning = "<arg type=... value=...> tag requires value parameter.";
String paramOutsideWarning = "<arg> tag outside <mlet> ... </mlet>.";
String requiresCodeWarning = "<mlet> tag requires either code or object parameter.";
String requiresJarsWarning = "<mlet> tag requires archive parameter.";
URLConnection conn;
conn = url.openConnection();
Reader in = new BufferedReader(new InputStreamReader(conn.getInputStream(),
UTF_8));
// The original URL may have been redirected - this
// sets it to whatever URL/codebase we ended up getting
//
url = conn.getURL();
List<MLetContent> mlets = new ArrayList<>();
Map<String,String> atts = null;
List<String> types = new ArrayList<>();
List<String> values = new ArrayList<>();
// debug("parse","*** Parsing " + url );
while(true) {
c = in.read();
if (c == -1)
break;
if (c == '<') {
c = in.read();
if (c == '/') {
c = in.read();
String nm = scanIdentifier(in);
if (c != '>')
throw new IOException("Missing '>' in tag");
if (nm.equalsIgnoreCase(tag)) {
if (atts != null) {
mlets.add(new MLetContent(url, atts, types, values));
}
atts = null;
types = new ArrayList<>();
values = new ArrayList<>();
}
} else {
String nm = scanIdentifier(in);
if (nm.equalsIgnoreCase("arg")) {
Map<String,String> t = scanTag(in);
String att = t.get("type");
if (att == null) {
MLET_LOGGER.log(Level.TRACE, requiresTypeWarning);
throw new IOException(requiresTypeWarning);
} else {
if (atts != null) {
types.add(att);
} else {
MLET_LOGGER.log(Level.TRACE, paramOutsideWarning);
throw new IOException(paramOutsideWarning);
}
}
String val = t.get("value");
if (val == null) {
MLET_LOGGER.log(Level.TRACE, requiresValueWarning);
throw new IOException(requiresValueWarning);
} else {
if (atts != null) {
values.add(val);
} else {
MLET_LOGGER.log(Level.TRACE, paramOutsideWarning);
throw new IOException(paramOutsideWarning);
}
}
} else {
if (nm.equalsIgnoreCase(tag)) {
atts = scanTag(in);
if (atts.get("code") == null && atts.get("object") == null) {
MLET_LOGGER.log(Level.TRACE, requiresCodeWarning);
throw new IOException(requiresCodeWarning);
}
if (atts.get("archive") == null) {
MLET_LOGGER.log(Level.TRACE, requiresJarsWarning);
throw new IOException(requiresJarsWarning);
}
}
}
}
}
}
in.close();
return mlets;
}
/**
* Parse the document pointed by the URL urlname
*/
@SuppressWarnings("removal")
public List<MLetContent> parseURL(String urlname) throws IOException {
// Parse the document
//
URL url;
if (urlname.indexOf(':') <= 1) {
String userDir = System.getProperty("user.dir");
String prot;
if (userDir.charAt(0) == '/' ||
userDir.charAt(0) == File.separatorChar) {
prot = "file:";
} else {
prot = "file:/";
}
url =
new URL(prot + userDir.replace(File.separatorChar, '/') + "/");
url = new URL(url, urlname);
} else {
url = new URL(urlname);
}
// Return list of parsed MLets
//
return parse(url);
}
}

View File

@ -1,105 +0,0 @@
/*
* Copyright (c) 2002, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package javax.management.loading;
import java.net.URL;
import java.net.URLStreamHandlerFactory;
/**
* An MLet that is not added to the {@link ClassLoaderRepository}.
* This class acts exactly like its parent class, {@link MLet}, with
* one exception. When a PrivateMLet is registered in an MBean
* server, it is not added to that MBean server's {@link
* ClassLoaderRepository}. This is true because this class implements
* the interface {@link PrivateClassLoader}.
*
* @deprecated This API is part of Management Applets (m-lets), which is a legacy feature that allows loading
* of remote MBeans. This feature is not usable without a Security Manager, which is deprecated and subject to
* removal in a future release. Consequently, this API is also deprecated and subject to removal. There is no replacement.
*
* @since 1.5
*/
@Deprecated(since="20", forRemoval=true)
@SuppressWarnings({"serial", "removal"}) // Externalizable class w/o no-arg c'tor
public class PrivateMLet extends MLet implements PrivateClassLoader {
private static final long serialVersionUID = 2503458973393711979L;
/**
* Constructs a new PrivateMLet for the specified URLs using the
* default delegation parent ClassLoader. The URLs will be
* searched in the order specified for classes and resources
* after first searching in the parent class loader.
*
* @param urls The URLs from which to load classes and resources.
* @param delegateToCLR True if, when a class is not found in
* either the parent ClassLoader or the URLs, the MLet should delegate
* to its containing MBeanServer's {@link ClassLoaderRepository}.
*
*/
public PrivateMLet(URL[] urls, boolean delegateToCLR) {
super(urls, delegateToCLR);
}
/**
* Constructs a new PrivateMLet for the given URLs. The URLs will
* be searched in the order specified for classes and resources
* after first searching in the specified parent class loader.
* The parent argument will be used as the parent class loader
* for delegation.
*
* @param urls The URLs from which to load classes and resources.
* @param parent The parent class loader for delegation.
* @param delegateToCLR True if, when a class is not found in
* either the parent ClassLoader or the URLs, the MLet should delegate
* to its containing MBeanServer's {@link ClassLoaderRepository}.
*
*/
public PrivateMLet(URL[] urls, ClassLoader parent, boolean delegateToCLR) {
super(urls, parent, delegateToCLR);
}
/**
* Constructs a new PrivateMLet for the specified URLs, parent
* class loader, and URLStreamHandlerFactory. The parent argument
* will be used as the parent class loader for delegation. The
* factory argument will be used as the stream handler factory to
* obtain protocol handlers when creating new URLs.
*
* @param urls The URLs from which to load classes and resources.
* @param parent The parent class loader for delegation.
* @param factory The URLStreamHandlerFactory to use when creating URLs.
* @param delegateToCLR True if, when a class is not found in
* either the parent ClassLoader or the URLs, the MLet should delegate
* to its containing MBeanServer's {@link ClassLoaderRepository}.
*
*/
public PrivateMLet(URL[] urls,
ClassLoader parent,
URLStreamHandlerFactory factory,
boolean delegateToCLR) {
super(urls, parent, factory, delegateToCLR);
}
}

View File

@ -2,7 +2,7 @@
<head>
<title>javax.management.loading package</title>
<!--
Copyright (c) 1999, 2017, 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,15 +39,7 @@ questions.
ObjectName, Object[], String[])}, and to instantiate arbitrary
objects via the method {@link
javax.management.MBeanServer#instantiate(String, ObjectName,
Object[], String[])}. The {@link
javax.management.loading.MLet MLet} class is an example of
such an MBean. It is a {@link java.net.URLClassLoader
URLClassLoader}, so the list of URLs to load classes from can
be configured.</p>
<p>Additionally, an <code>MLet</code> can read a configuration
file that specifies a set of MBeans to be registered in the same
MBean Server as the <code>MLet</code>.</p>
Object[], String[])}.</p>
<p>Every MBean Server has a <em>class loader repository</em>
containing all MBeans registered in that MBean Server that
@ -55,16 +47,11 @@ questions.
loader repository is used by the forms of the
<code>createMBean</code> and <code>instantiate</code> methods
in the {@link javax.management.MBeanServer MBeanServer}
interface that do not have an explicit loader parameter. It
is also used by the <code>MLet</code> class when it does not
find a class in its own set of URLs.</p>
interface that do not have an explicit loader parameter.</p>
<p>If an MBean implements the interface {@link
javax.management.loading.PrivateClassLoader PrivateClassLoader},
then it is not added to the class loader repository. The class
{@link javax.management.loading.PrivateMLet PrivateMLet} is a
subclass of <code>MLet</code> that implements
<code>PrivateClassLoader</code>.</p>
then it is not added to the class loader repository.</p>
@see <a id="spec" href="https://jcp.org/aboutJava/communityprocess/mrel/jsr160/index2.html">
JMX Specification, version 1.4</a>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -30,9 +30,10 @@
*
* @run clean ClassLeakTest
* @run build ClassLeakTest
* @run main ClassLeakTest
* @run main/othervm ClassLeakTest
*/
import java.lang.management.ManagementFactory;
import java.lang.ref.WeakReference;
import java.io.File;
import java.nio.file.Paths;
@ -48,7 +49,6 @@ public class ClassLeakTest {
"Standard MBean does not retain a reference to " +
"the MBean's class");
String[] cpaths = System.getProperty("test.classes", ".")
.split(File.pathSeparator);
URL[] urls = new URL[cpaths.length];
@ -56,25 +56,24 @@ public class ClassLeakTest {
urls[i] = Paths.get(cpaths[i]).toUri().toURL();
}
@SuppressWarnings("removal")
PrivateMLet mlet = new PrivateMLet(urls, null, false);
Class<?> shadowClass = mlet.loadClass(TestMBean.class.getName());
Test loaderMBean = new Test(urls);
Class<?> shadowClass = loaderMBean.loadClass(TestMBean.class.getName());
if (shadowClass == TestMBean.class) {
System.out.println("TEST INVALID: MLet got original " +
System.out.println("TEST INVALID: MBean got original " +
"TestMBean not shadow");
System.exit(1);
}
shadowClass = null;
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
ObjectName mletName = new ObjectName("x:type=mlet");
mbs.registerMBean(mlet, mletName);
ObjectName loaderMBeanName = new ObjectName("x:name=loader");
mbs.registerMBean(loaderMBean, loaderMBeanName);
ObjectName testName = new ObjectName("x:type=test");
mbs.createMBean(Test.class.getName(), testName, mletName);
mbs.createMBean(Test.class.getName(), testName, loaderMBeanName);
ClassLoader testLoader = mbs.getClassLoaderFor(testName);
if (testLoader != mlet) {
if (testLoader != loaderMBean) {
System.out.println("TEST INVALID: MBean's class loader is not " +
"MLet: " + testLoader);
System.exit(1);
@ -109,20 +108,19 @@ public class ClassLeakTest {
System.exit(1);
}
WeakReference mbeanRef = new WeakReference(loaderMBean);
mbs.unregisterMBean(testName);
mbs.unregisterMBean(mletName);
WeakReference mletRef = new WeakReference(mlet);
mlet = null;
mbs.unregisterMBean(loaderMBeanName);
loaderMBean = null;
System.out.println("MBean registered and unregistered, waiting for " +
"garbage collector to collect class loader");
for (int i = 0; i < 10000 && mletRef.get() != null; i++) {
for (int i = 0; i < 10000 && mbeanRef.get() != null; i++) {
System.gc();
Thread.sleep(1);
}
if (mletRef.get() == null)
if (mbeanRef.get() == null)
System.out.println("Test passed: class loader was GC'd");
else {
System.out.println("TEST FAILED: class loader was not GC'd");
@ -136,10 +134,13 @@ public class ClassLeakTest {
public void setA(int a);
}
public static class Test implements TestMBean {
public Test() {}
public Test(int x) {}
public static class Test extends URLClassLoader implements TestMBean, PrivateClassLoader {
public Test() {
super(new URL[0], null);
}
public Test(URL[] urls) {
super(urls, null);
}
public void bogus() {}
public int getA() {return 0;}
public void setA(int a) {}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 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
@ -34,8 +34,8 @@
import javax.management.*;
import java.io.Serializable;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.EnumSet;
import javax.management.loading.MLet;
public class PostExceptionTest {
@ -95,7 +95,7 @@ public class PostExceptionTest {
// We're going to test each cases, using each of the 4 createMBean
// forms + registerMBean in turn to create the MBean.
// Wich method is used to create the MBean is indicated by "how"
// Which method is used to create the MBean is indicated by "how"
//
for (Case caze:cases) {
for (CREATE how : CREATE.values()) {
@ -375,7 +375,7 @@ public class PostExceptionTest {
MBeanServer server, ObjectName name) throws Exception {
ExceptionallyHackyWombat.t = t;
ExceptionallyHackyWombat.w = where;
final ObjectName loaderName = registerMLet(server);
final ObjectName loaderName = registerMB(server);
return server.createMBean(
ExceptionallyHackyWombat.class.getName(),
name, loaderName);
@ -404,7 +404,7 @@ public class PostExceptionTest {
};
return server.createMBean(
ExceptionalWombat.class.getName(), name,
registerMLet(server), params, signature);
registerMB(server), params, signature);
}
},
REGISTER() {
@ -422,25 +422,23 @@ public class PostExceptionTest {
public abstract ObjectInstance create(Throwable t, EnumSet<WHERE> where,
MBeanServer server, ObjectName name) throws Exception;
// This is a bit of a hack - we use an MLet that delegates to the
// Create an MBean that delegates to the
// System ClassLoader so that we can use createMBean form #2 and #3
// while still using the same class loader (system).
// This is necessary to make the ExceptionallyHackyWombatMBean work ;-)
//
public ObjectName registerMLet(MBeanServer server) throws Exception {
final ObjectName name = new ObjectName("test:type=MLet");
public ObjectName registerMB(MBeanServer server) throws Exception {
final ObjectName name = new ObjectName("test:type=TestMBean");
if (server.isRegistered(name)) {
return name;
}
@SuppressWarnings("removal")
final MLet mlet = new MLet(new URL[0],
ClassLoader.getSystemClassLoader());
return server.registerMBean(mlet, name).getObjectName();
final TestMBean mbean = new Test();
return server.registerMBean(mbean, name).getObjectName();
}
}
/**
*A Wombat MBean that can throw exceptions or errors in any of the
* A Wombat MBean that can throw exceptions or errors in any of the
* MBeanRegistration methods.
*/
public static interface ExceptionalWombatMBean {
@ -514,4 +512,13 @@ public class PostExceptionTest {
}
}
public static interface TestMBean {
}
public static class Test extends URLClassLoader implements TestMBean {
public Test() {
super(new URL[0], ClassLoader.getSystemClassLoader());
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 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
@ -51,7 +51,7 @@ public class ArrayClassTest {
urls[i] = Paths.get(cpaths[i]).toUri().toURL();
}
// Create an MLet that can load the same class names but
// Create a SpyLoader MBean that can load the same class names but
// will produce different results.
ClassLoader loader = new SpyLoader(urls);
ObjectName loaderName = new ObjectName("test:type=SpyLoader");
@ -105,10 +105,6 @@ public class ArrayClassTest {
public static interface SpyLoaderMBean {}
/* We originally had this extend MLet but for some reason that
stopped the bug from happening. Some side-effect of registering
the MLet in the MBean server caused it not to fail when asked
to load Z[]. */
public static class SpyLoader extends URLClassLoader
implements SpyLoaderMBean, PrivateClassLoader {
public SpyLoader(URL[] urls) {
@ -117,19 +113,6 @@ public class ArrayClassTest {
super(urls, null);
}
/*
public Class loadClass(String name) throws ClassNotFoundException {
System.out.println("loadClass: " + name);
return super.loadClass(name);
}
public Class loadClass(String name, boolean resolve)
throws ClassNotFoundException {
System.out.println("loadClass: " + name + ", " + resolve);
return super.loadClass(name, resolve);
}
*/
public Class findClass(String name) throws ClassNotFoundException {
System.out.println("findClass: " + name);
if (false)

View File

@ -1,75 +0,0 @@
/*
* Copyright (c) 2006, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6500139
* @summary Test parsing error when the mlet file is
* located in the web server's document root.
* @author Luis-Miguel Alventosa
*
* @run clean DocumentRootTest
* @run build DocumentRootTest
* @run main DocumentRootTest
*/
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import javax.management.loading.MLetContent;
@SuppressWarnings("removal")
public class DocumentRootTest {
public static int test(URL documentBase, URL codeBase) {
int error = 0;
MLetContent mc = new MLetContent(
documentBase,
new HashMap<String,String>(),
new ArrayList<String>(),
new ArrayList<String>());
System.out.println("\nACTUAL DOCUMENT BASE = " + mc.getDocumentBase());
System.out.println("EXPECTED DOCUMENT BASE = " + documentBase);
if (!documentBase.equals(mc.getDocumentBase())) {
System.out.println("ERROR: Wrong document base");
error++;
};
System.out.println("ACTUAL CODEBASE = " + mc.getCodeBase());
System.out.println("EXPECTED CODEBASE = " + codeBase);
if (!codeBase.equals(mc.getCodeBase())) {
System.out.println("ERROR: Wrong code base");
error++;
};
return error;
}
public static void main(String[] args) throws Exception {
int error = 0;
error += test(new URL("file:/mlet.txt"), new URL("file:/"));
error += test(new URL("http://localhost/mlet.txt"), new URL("http://localhost/"));
if (error > 0) {
System.out.println("\nTest FAILED!\n");
throw new IllegalArgumentException("Test FAILED!");
} else {
System.out.println("\nTest PASSED!\n");
}
}
}

View File

@ -1,105 +0,0 @@
/*
* Copyright (c) 2004, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5018593
* @summary Test that calling getMBeansFromURL(url) with a bogus URL on a
* given MLet instance throws a ServiceNotFoundException exception
* with a non null cause.
* @author Luis-Miguel Alventosa
*
* @run clean GetMBeansFromURLTest
* @run build GetMBeansFromURLTest
* @run main GetMBeansFromURLTest
*/
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.ServiceNotFoundException;
import javax.management.loading.MLet;
@SuppressWarnings("removal")
public class GetMBeansFromURLTest {
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
try {
mlet.getMBeansFromURL("bogus://whatever");
System.out.println("TEST FAILED: Expected " +
ServiceNotFoundException.class +
" exception not thrown.");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got null cause in " +
ServiceNotFoundException.class +
" exception.");
error = true;
} else {
System.out.println("TEST PASSED: Got non-null cause in " +
ServiceNotFoundException.class +
" exception.");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
}

View File

@ -1,155 +0,0 @@
/*
* Copyright (c) 2004, 2020, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4969756
* @summary Test that the same native library coming from the same jar file can
* be loaded twice by two different MLets on the same JVM without conflict.
* @author Luis-Miguel Alventosa
*
* @run clean LibraryLoaderTest
* @run build LibraryLoaderTest
* @run main/othervm LibraryLoaderTest
*/
import java.io.File;
import java.util.Set;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.ReflectionException;
public class LibraryLoaderTest {
private static final String mletInfo[][] = {
{"testDomain:type=MLet,index=0", "UseNativeLib0.html"},
{"testDomain:type=MLet,index=1", "UseNativeLib1.html"}
};
public static void main(String args[]) throws Exception {
String osName = System.getProperty("os.name");
System.out.println("os.name=" + osName);
String osArch = System.getProperty("os.arch");
System.out.println("os.name=" + osArch);
// Check for supported platforms:
//
// Windows/x86
//
if ((!(osName.startsWith("Windows") && osArch.equals("x86")))) {
System.out.println(
"This test runs only on Windows/x86 platforms");
System.out.println("Bye! Bye!");
return;
}
String libPath = System.getProperty("java.library.path");
System.out.println("java.library.path=" + libPath);
String testSrc = System.getProperty("test.src");
System.out.println("test.src=" + testSrc);
String workingDir = System.getProperty("user.dir");
System.out.println("user.dir=" + workingDir);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
// Create MBeanServer
//
MBeanServer server = MBeanServerFactory.newMBeanServer();
// Create MLet instances and call getRandom on the loaded MBeans
//
for (int i = 0; i < mletInfo.length; i++) {
// Create ObjectName for MLet
//
ObjectName mlet = new ObjectName(mletInfo[i][0]);
server.createMBean("javax.management.loading.MLet", mlet);
System.out.println("MLet = " + mlet);
// Display old library directory and set it to test.classes
//
String libraryDirectory =
(String) server.getAttribute(mlet, "LibraryDirectory");
System.out.println("Old Library Directory = " +
libraryDirectory);
Attribute attribute =
new Attribute("LibraryDirectory", workingDir);
server.setAttribute(mlet, attribute);
libraryDirectory =
(String) server.getAttribute(mlet, "LibraryDirectory");
System.out.println("New Library Directory = " +
libraryDirectory);
// Get MBeans from URL
//
String mletURL = urlCodebase + mletInfo[i][1];
System.out.println("MLet URL = " + mletURL);
Object[] params = new Object[] { mletURL };
String[] signature = new String[] {"java.lang.String"};
Object res[] = ((Set<?>) server.invoke(mlet,
"getMBeansFromURL",
params,
signature)).toArray();
// Iterate through all the loaded MBeans
//
for (int j = 0; j < res.length; j++) {
// Now ensure none of the returned objects is a Throwable
//
if (res[j] instanceof Throwable) {
((Throwable) res[j]).printStackTrace(System.out);
throw new Exception("Failed to load the MBean #" + j
,(Throwable)res[j]);
}
// On each of the loaded MBeans, try to invoke their
// native operation
//
Object result = null;
try {
ObjectName mbean =
((ObjectInstance) res[j]).getObjectName();
result = server.getAttribute(mbean, "Random");
System.out.println("MBean #" + j + " = " + mbean);
System.out.println("Random number = " + result);
} catch (ReflectionException e) {
e.getTargetException().printStackTrace(System.out);
throw new Exception ("A ReflectionException "
+ "occured when attempting to invoke "
+ "a native library based operation.",
e.getTargetException());
}
}
}
}
}

View File

@ -1,19 +0,0 @@
<HTML>
<MLET
CODE = "UseNativeLib.class"
ARCHIVE = "native.jar"
NAME = "mletTests:type=nativeLibLoading,index=0.0"
>
</MLET>
<MLET
CODE = "UseNativeLib.class"
ARCHIVE = "native.jar"
NAME = "mletTests:type=nativeLibLoading,index=0.1"
>
</MLET>
<BODY>
Test MLet.
</BODY>
</HTML>

View File

@ -1,19 +0,0 @@
<HTML>
<MLET
CODE = "UseNativeLib.class"
ARCHIVE = "native.jar"
NAME = "mletTests:type=nativeLibLoading,index=1.0"
>
</MLET>
<MLET
CODE = "UseNativeLib.class"
ARCHIVE = "native.jar"
NAME = "mletTests:type=nativeLibLoading,index=1.1"
>
</MLET>
<BODY>
Test MLet.
</BODY>
</HTML>

View File

@ -1,15 +0,0 @@
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_UseNativeLib_getRandom(JNIEnv *env, jobject obj) {
return rand();
}
#ifdef __cplusplus
}
#endif

View File

@ -1,15 +0,0 @@
#include <jni.h>
#ifndef RandomGen
#define RandomGen
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jint JNICALL Java_RandomGen_getRandom
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2004, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public class UseNativeLib implements java.io.Serializable, UseNativeLibMBean {
public native int getRandom();
static {
try {
System.loadLibrary("genrandom");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -1,26 +0,0 @@
/*
* Copyright (c) 2004, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
public interface UseNativeLibMBean {
public int getRandom();
}

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 2003, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4836468
* @summary Test that the getClassLoaderRepository permission is not necessary
* for the test codebase as it is executed by the MLet code using
* doPrivileged.
* @author Luis-Miguel Alventosa
*
* @run clean MLetCommand
* @run build MLetCommand
* @run main/othervm/java.security.policy=policy MLetCommand
*/
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import java.io.File;
@SuppressWarnings("removal")
public class MLetCommand {
public static void main(String[] args) throws Exception {
if (System.getSecurityManager() == null)
throw new IllegalStateException("No security manager installed!");
System.out.println("java.security.policy=" +
System.getProperty("java.security.policy"));
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Register the MLetMBean
//
System.out.println("Create MLet MBean");
ObjectName mlet = new ObjectName("MLetTest:name=MLetMBean");
mbs.createMBean("javax.management.loading.MLet", mlet);
// Test OK!
//
System.out.println("Bye! Bye!");
}
}

View File

@ -1,8 +0,0 @@
grant {
permission java.util.PropertyPermission "*", "read";
permission javax.management.MBeanServerPermission "createMBeanServer";
permission javax.management.MBeanPermission "javax.management.loading.MLet#-[-]", "instantiate";
permission javax.management.MBeanPermission "javax.management.loading.MLet#-[MLetTest:name=MLetMBean]", "registerMBean";
permission java.lang.RuntimePermission "createClassLoader";
};

View File

@ -1,146 +0,0 @@
/*
* Copyright (c) 2004, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4796780
* @summary The class MLetContentTest becomes public
* @author Shanliang JIANG
*
* @run clean MLetContentTest
* @run build MLetContentTest
* @run main MLetContentTest
*/
import java.util.*;
import java.net.*;
import javax.management.loading.*;
@SuppressWarnings("removal")
public class MLetContentTest {
public static void main(String[] args) throws Exception {
System.out.println(">>> General test for the public class MLetContent.");
Map<String,String> attributes = new HashMap();
attributes.put("archive", archive);
attributes.put("Archive", "hahaha");
attributes.put("code", code);
attributes.put("codE", "hihi");
attributes.put("object", object);
attributes.put("obJect", "toto");
attributes.put("name", name);
attributes.put("NAME", "titi");
attributes.put("version", version);
attributes.put("VeRsIoN", "tttt");
List<String> types = new ArrayList();
types.add("my type");
List<String> values = new ArrayList();
values.add("my values");
URL url = new URL(baseUrl+myfile);
MLetContent content = new MLetContent(url, attributes, types, values);
if (!attributes.equals(content.getAttributes())) {
throw new RuntimeException("The user specific attributes are changed.");
}
if (!url.equals(content.getDocumentBase())) {
throw new RuntimeException("The user specific document bas is changed.");
}
if (!archive.equals(content.getJarFiles())) {
throw new RuntimeException("The user specific archive files are changed.");
}
if (!code.equals(content.getCode())) {
throw new RuntimeException("The user specific code is changed.");
}
if (!object.equals(content.getSerializedObject())) {
throw new RuntimeException("The user specific object is changed.");
}
if (!name.equals(content.getName())) {
throw new RuntimeException("The user specific name is changed.");
}
if (!version.equals(content.getVersion())) {
throw new RuntimeException("The user specific version is changed.");
}
if (!types.equals(content.getParameterTypes())) {
throw new RuntimeException("The user specific types are changed.");
}
if (!values.equals(content.getParameterValues())) {
throw new RuntimeException("The user specific values are changed.");
}
if (!baseUrl.equals(content.getCodeBase().toString())) {
throw new RuntimeException("The user specific base url are changed.");
}
url = new URL(baseUrl);
attributes.put("codebase", codebase);
content = new MLetContent(url, attributes, types, values);
if (!content.getCodeBase().toString().equals(baseUrl+codebase)) {
throw new RuntimeException("The user specific base url are changed.");
}
final MyMLet myMlet = new MyMLet();
if (myMlet.check(null, null, null, content) != content.getCodeBase()) {
throw new RuntimeException("Failed to overrid the protected methed check");
}
System.out.println(">>> The test is well passed.");
}
private static class MyMLet extends MLet {
public URL check(String version,
URL codebase,
String jarfile,
MLetContent content) {
return content.getCodeBase();
}
}
private static final String archive = "my jarfile";
private static final String code = "my code";
private static final String object = "my object";
private static final String name = "my name";
private static final String version = "my version";
private static final String myfile = "My file";
private static final String baseUrl = "file:/tmp/test/";
private final static String codebase = "my code base/";
}

View File

@ -1,93 +0,0 @@
/*
* Copyright (c) 2014, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.management.loading.MLet;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import static org.testng.Assert.*;
/*
* @test
* @bug 8058089
* @summary Tests various internal functions provided by MLet for correctness
* @author Jaroslav Bachorik
* @modules java.management/javax.management.loading:open
* @run testng MLetInternalsTest
*/
@SuppressWarnings("removal")
public class MLetInternalsTest {
private final static String CONSTRUCT_PARAMETER = "constructParameter";
private final static Map<String, Method> testedMethods = new HashMap<>();
@BeforeClass
public static void setupClass() {
testedMethods.clear();
try {
Method m = MLet.class.getDeclaredMethod(
CONSTRUCT_PARAMETER,
String.class, String.class
);
m.setAccessible(true);
testedMethods.put(CONSTRUCT_PARAMETER, m);
} catch (Exception ex) {
throw new Error(ex);
}
}
private MLet mlet;
@BeforeTest
public void setupTest() {
mlet = new MLet();
}
@Test
public void testConstructParameter() throws Exception {
assertEquals(constructParameter("120", "int"), 120);
assertEquals(constructParameter("120", "java.lang.Integer"), Integer.valueOf(120));
assertEquals(constructParameter("120", "long"), 120L);
assertEquals(constructParameter("120", "java.lang.Long"), Long.valueOf(120));
assertEquals(constructParameter("120.0", "float"), 120.0f);
assertEquals(constructParameter("120.0", "java.lang.Float"), Float.valueOf(120.0f));
assertEquals(constructParameter("120.0", "double"), 120.0d);
assertEquals(constructParameter("120", "java.lang.Double"), Double.valueOf(120d));
assertEquals(constructParameter("120", "java.lang.String"), "120");
assertEquals(constructParameter("120", "byte"), (byte)120);
assertEquals(constructParameter("120", "java.lang.Byte"), (byte)120);
assertEquals(constructParameter("120", "short"), (short)120);
assertEquals(constructParameter("120", "java.lang.Short"), (short)120);
assertEquals(constructParameter("true", "boolean"), true);
assertEquals(constructParameter("true", "java.lang.Boolean"), Boolean.valueOf(true));
}
private Object constructParameter(String param, String type) throws Exception {
return testedMethods.get(CONSTRUCT_PARAMETER).invoke(mlet, param, type);
}
}

View File

@ -1,110 +0,0 @@
/*
* Copyright (c) 2015, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 7065236
* @summary Checking MletParser for Locale insensitive strings
* @author Harsha Wardhana B
*
* @run clean MletParserLocaleTest
* @run build MletParserLocaleTest
* @run main/othervm MletParserLocaleTest mlet4.html
*/
import java.io.File;
import java.util.Locale;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.loading.MLet;
@SuppressWarnings("removal")
public class MletParserLocaleTest {
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Get Default Locale
Locale loc = Locale.getDefault();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
// Change default Locale to Turkish
Locale.setDefault(Locale.of("tr", "TR"));
mlet.getMBeansFromURL(mletFile);
System.out.println("Test Passes");
} catch (Exception e) {
error = true;
e.printStackTrace(System.out);
}finally {
Locale.setDefault(loc);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
}

View File

@ -1,123 +0,0 @@
/*
* Copyright (c) 2005, 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 5042364
* @summary Malformed MLet text file causes infinite loop in parser.
* The MLetParser goes into an infinite loop when a tag is not
* terminated with the corresponding '>' and an opening '<' for
* the subsequent tag is encountered.
* @author Luis-Miguel Alventosa
*
* @run clean ParserInfiniteLoopTest
* @run build ParserInfiniteLoopTest
* @run main/othervm ParserInfiniteLoopTest mlet1.html
* @run main/othervm ParserInfiniteLoopTest mlet2.html
* @run main/othervm ParserInfiniteLoopTest mlet3.html
*/
import java.io.File;
import java.io.IOException;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.ServiceNotFoundException;
import javax.management.loading.MLet;
@SuppressWarnings("removal")
public class ParserInfiniteLoopTest {
public static void main(String[] args) throws Exception {
boolean error = false;
// Instantiate the MBean server
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Instantiate an MLet
//
System.out.println("Create the MLet");
MLet mlet = new MLet();
// Register the MLet MBean with the MBeanServer
//
System.out.println("Register the MLet MBean");
ObjectName mletObjectName = new ObjectName("Test:type=MLet");
mbs.registerMBean(mlet, mletObjectName);
// Call getMBeansFromURL
//
System.out.println("Call mlet.getMBeansFromURL(<url>)");
String testSrc = System.getProperty("test.src");
System.out.println("test.src = " + testSrc);
String urlCodebase;
if (testSrc.startsWith("/")) {
urlCodebase =
"file:" + testSrc.replace(File.separatorChar, '/') + "/";
} else {
urlCodebase =
"file:/" + testSrc.replace(File.separatorChar, '/') + "/";
}
String mletFile = urlCodebase + args[0];
System.out.println("MLet File = " + mletFile);
try {
mlet.getMBeansFromURL(mletFile);
System.out.println(
"TEST FAILED: Expected ServiceNotFoundException not thrown");
error = true;
} catch (ServiceNotFoundException e) {
if (e.getCause() == null) {
System.out.println("TEST FAILED: Got unexpected null cause " +
"in ServiceNotFoundException");
error = true;
} else if (!(e.getCause() instanceof IOException)) {
System.out.println("TEST FAILED: Got unexpected non-null " +
"cause in ServiceNotFoundException");
error = true;
} else {
System.out.println("TEST PASSED: Got expected non-null " +
"cause in ServiceNotFoundException");
error = false;
}
e.printStackTrace(System.out);
}
// Unregister the MLet MBean
//
System.out.println("Unregister the MLet MBean");
mbs.unregisterMBean(mletObjectName);
// Release MBean server
//
System.out.println("Release the MBean server");
MBeanServerFactory.releaseMBeanServer(mbs);
// End Test
//
System.out.println("Bye! Bye!");
if (error) System.exit(1);
}
}

View File

@ -1,2 +0,0 @@
<MLET CODE=HelloWorld ARCHIVE="helloworld.jar"
</MLET>

View File

@ -1,2 +0,0 @@
<MLET CODE=HelloWorld ARCHIVE="helloworld.jar">
</MLET

View File

@ -1,3 +0,0 @@
<MLET CODE=HelloWorld ARCHIVE="helloworld.jar">
<ARG TYPE=argumentType VALUE=value
</MLET>

View File

@ -1,2 +0,0 @@
<MLET CODE=HelloWorld ARCHIVE="helloworld.jar">
</MLET>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
@ -35,6 +35,7 @@
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Map;
import javax.management.Attribute;
@ -45,8 +46,9 @@ import javax.management.MBeanOperationInfo;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.MXBean;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.loading.PrivateMLet;
import javax.management.loading.PrivateClassLoader;
import javax.management.openmbean.CompositeData;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
@ -60,7 +62,6 @@ public class MXBeanLoadingTest1 {
test.run((Map<String, Object>)null);
}
public void run(Map<String, Object> args) {
System.out.println("MXBeanLoadingTest1::run: Start") ;
@ -81,38 +82,36 @@ public class MXBeanLoadingTest1 {
+ ".class", "");
URL[] urls = new URL[]{new URL(clsLoadPath)};
@SuppressWarnings("removal")
PrivateMLet mlet = new PrivateMLet(urls, null, false);
Class<?> shadowClass = mlet.loadClass(TestMXBean.class.getName());
Loader loader = new Loader(urls);
Class<?> shadowClass = loader.loadClass(TestMXBean.class.getName());
if (shadowClass == TestMXBean.class) {
String message = "(ERROR) MLet got original TestMXBean, not shadow";
String message = "(ERROR) Loader got original TestMXBean, not shadow";
System.out.println(message);
throw new RuntimeException(message);
}
shadowClass = null;
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
ObjectName mletName = new ObjectName("x:type=mlet");
mbs.registerMBean(mlet, mletName);
ObjectName loaderName = new ObjectName("x:type=myloader");
mbs.registerMBean(loader, loaderName);
ObjectName testName = new ObjectName("x:type=test");
mbs.createMBean(Test.class.getName(), testName, mletName);
mbs.createMBean(Test.class.getName(), testName, loaderName);
// That test fails because the MXBean instance is accessed via
// a delegate OpenMBean which has
ClassLoader testLoader = mbs.getClassLoaderFor(testName);
if (testLoader != mlet) {
System.out.println("MLet " + mlet);
String message = "(ERROR) MXBean's class loader is not MLet: "
if (testLoader != loader) {
System.out.println("Loader " + loader);
String message = "(ERROR) MXBean's class loader is not Loader: "
+ testLoader;
System.out.println(message);
throw new RuntimeException(message);
}
testLoader = null;
// Cycle get/set/get of the attribute of type Luis.
// We check the set is effective.
CompositeData cd_B = (CompositeData)mbs.getAttribute(testName, "B");
@ -264,23 +263,20 @@ public class MXBeanLoadingTest1 {
throw new RuntimeException(message);
}
WeakReference<Loader> loaderRef = new WeakReference<>(loader);
mbs.unregisterMBean(testName);
mbs.unregisterMBean(mletName);
@SuppressWarnings("removal")
WeakReference<PrivateMLet> mletRef =
new WeakReference<PrivateMLet>(mlet);
mlet = null;
mbs.unregisterMBean(loaderName);
loader = null;
System.out.println("MXBean registered and unregistered, waiting for " +
"garbage collector to collect class loader");
for (int i = 0; i < 10000 && mletRef.get() != null; i++) {
for (int i = 0; i < 10000 && loaderRef.get() != null; i++) {
System.gc();
Thread.sleep(1);
}
if (mletRef.get() == null)
if (loaderRef.get() == null)
System.out.println("(OK) class loader was GC'd");
else {
String message = "(ERROR) Class loader was not GC'd";
@ -295,6 +291,14 @@ public class MXBeanLoadingTest1 {
System.out.println("MXBeanLoadingTest1::run: Done without any error") ;
}
public static interface LoaderMBean {
}
public static class Loader extends URLClassLoader implements LoaderMBean, PrivateClassLoader {
public Loader(URL[] urls) {
super(urls, null);
}
}
// I agree the use of the MXBean annotation and the MXBean suffix for the
// interface name are redundant but however harmless.

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -35,11 +35,10 @@
import java.util.*;
import javax.management.*;
import javax.management.relation.*;
import javax.management.loading.MLet;
import javax.management.timer.Timer;
public class NonArrayListTest {
@SuppressWarnings("removal") // use of MLet
public static void main(String[] args) throws Exception {
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
RelationService rs = new RelationService(true);
@ -51,18 +50,18 @@ public class NonArrayListTest {
RelationServiceMBean.class,
false);
ObjectName mlet1Name = new ObjectName("r:type=MLet,instance=1");
ObjectName mlet2Name = new ObjectName("r:type=MLet,instance=2");
mbs.createMBean(MLet.class.getName(), mlet1Name);
mbs.createMBean(MLet.class.getName(), mlet2Name);
ObjectName mb1Name = new ObjectName("r:type=Timer,instance=1");
ObjectName mb2Name = new ObjectName("r:type=Timer,instance=2");
mbs.createMBean(Timer.class.getName(), mb1Name);
mbs.createMBean(Timer.class.getName(), mb2Name);
RoleInfo leftRoleInfo = new RoleInfo("left", MLet.class.getName());
RoleInfo rightRoleInfo = new RoleInfo("right", MLet.class.getName());
RoleInfo leftRoleInfo = new RoleInfo("left", Timer.class.getName());
RoleInfo rightRoleInfo = new RoleInfo("right", Timer.class.getName());
ArrayList leftRoleValues =
new ArrayList(Arrays.asList(new ObjectName[] {mlet1Name}));
new ArrayList(Arrays.asList(new ObjectName[] {mb1Name}));
ArrayList rightRoleValues =
new ArrayList(Arrays.asList(new ObjectName[] {mlet2Name}));
new ArrayList(Arrays.asList(new ObjectName[] {mb2Name}));
Role leftRole = new Role("left", leftRoleValues);
Role rightRole = new Role("right", rightRoleValues);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -211,9 +211,8 @@ public class IdleTimeoutTest {
System.out.println("Operation[" + (i+1)
+"]: starting at " +
elapsed + "ms");
final String name = "d:type=mlet,instance=" + i;
mbs.createMBean("javax.management.loading.MLet",
new ObjectName(name));
final String name = "d:instance=" + i;
mbs.registerMBean(new Test(), new ObjectName(name));
if (i == (opCount-1))
startIdle = System.currentTimeMillis();
Thread.sleep(2);
@ -310,4 +309,17 @@ public class IdleTimeoutTest {
System.out.println("*** ------------------------------------------");
return true;
}
public static interface TestMBean {
public int getA();
public void setA(int a);
}
public static class Test implements TestMBean {
public Test() {}
public Test(int x) {}
public int getA() {return 0;}
public void setA(int a) {}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -49,13 +49,13 @@
will use the wrong loader for deserialization and the attempt to
invoke the target MBean with the deserialized object will fail.
We test this as follows. We fabricate an MLet that has the same set
We test this as follows. We create an MBean that has the same set
of URLs as the 160 class loader, which we assume is the system class
loader (or at least, it is a URLClassLoader). This MLet is
loader (or at least, it is a URLClassLoader). This MBean is
therefore a "shadow class loader" -- for every class name known to
the 160 class loader, it can load the same name, but the result is
not the same class, since it has not been loaded by the same loader.
Then, we use the MLet to create an RMIConnectorServer MBean. This
Then, we use the MBean to create an RMIConnectorServer MBean. This
MBean is an instance of "shadow RMIConnectorServer", and its
constructor has a parameter of type "shadow JMXServiceURL". If the
constructor is invoked with "real JMXServiceURL" it will fail.
@ -72,10 +72,10 @@ import javax.management.remote.*;
import javax.management.remote.rmi.RMIConnectorServer;
public class TargetMBeanTest {
private static final ObjectName mletName;
private static final ObjectName mbeanName;
static {
try {
mletName = new ObjectName("x:type=mlet");
mbeanName = new ObjectName("x:type=TestMBean");
} catch (Exception e) {
e.printStackTrace();
throw new Error();
@ -101,17 +101,16 @@ public class TargetMBeanTest {
URLClassLoader jrcl = (URLClassLoader) jmxRemoteClassLoader;
URL[] urls = jrcl.getURLs();
@SuppressWarnings("removal")
PrivateMLet mlet = new PrivateMLet(urls, null, false);
Class shadowClass = mlet.loadClass(JMXServiceURL.class.getName());
TestMBean mbean = new Test(urls);
Class shadowClass = mbean.loadClass(JMXServiceURL.class.getName());
if (shadowClass == JMXServiceURL.class) {
System.out.println("TEST INVALID: MLet got original " +
System.out.println("TEST INVALID: Test MBean got original " +
"JMXServiceURL not shadow");
System.exit(1);
}
MBeanServer mbs = MBeanServerFactory.newMBeanServer();
mbs.registerMBean(mlet, mletName);
mbs.registerMBean(mbean, mbeanName);
final String[] protos = {"rmi", "iiop", "jmxmp"};
boolean ok = true;
@ -155,7 +154,7 @@ public class TargetMBeanTest {
ObjectName on = new ObjectName("x:proto=" + proto + ",ok=yes");
mbsc.createMBean(RMIConnectorServer.class.getName(),
on,
mletName,
mbeanName,
new Object[] {rmiurl, null},
new String[] {JMXServiceURL.class.getName(),
Map.class.getName()});
@ -166,4 +165,18 @@ public class TargetMBeanTest {
cs.stop();
return true;
}
public static interface TestMBean {
public Class<?> loadClass(String name) throws ClassNotFoundException;
}
public static class Test extends URLClassLoader implements TestMBean {
public Test(URL[] urls) {
super(urls, null);
}
public Class<?> loadClass(String name) throws ClassNotFoundException {
return loadClass(name, false);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -48,7 +48,7 @@ import javax.management.Notification;
import javax.management.NotificationFilter;
import javax.management.NotificationFilterSupport;
import javax.management.ObjectName;
import javax.management.loading.MLet;
import javax.management.timer.Timer;
import javax.management.remote.NotificationResult;
import javax.management.remote.TargetedNotification;
@ -80,7 +80,6 @@ public class NotificationBufferTest {
}
}
@SuppressWarnings("removal") // use of MLet
private static boolean test() throws Exception {
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
@ -121,7 +120,7 @@ public class NotificationBufferTest {
}
System.out.println("Got earliest==next in initial fetch, OK");
mbs.createMBean(MLet.class.getName(), null);
mbs.createMBean(Timer.class.getName(), new ObjectName(":type=Timer"));
mbs.createMBean(NotificationSender.class.getName(), senderName);
NotificationSenderMBean sender = (NotificationSenderMBean)

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2004, 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
@ -91,12 +91,6 @@ public class RMIAltAuthTest {
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Register the ClassPathClassLoaderMBean
//
System.out.println("Create ClassPathClassLoader MBean");
ObjectName cpcl =
new ObjectName("ClassLoader:name=ClassPathClassLoader");
mbs.createMBean("javax.management.loading.MLet", cpcl);
// Register the SimpleStandardMBean
//
System.out.println("Create SimpleStandard MBean");

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 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
@ -89,12 +89,6 @@ public class RMIPasswdAuthTest {
//
System.out.println("Create the MBean server");
MBeanServer mbs = MBeanServerFactory.createMBeanServer();
// Register the ClassPathClassLoaderMBean
//
System.out.println("Create ClassPathClassLoader MBean");
ObjectName cpcl =
new ObjectName("ClassLoader:name=ClassPathClassLoader");
mbs.createMBean("javax.management.loading.MLet", cpcl);
// Register the SimpleStandardMBean
//
System.out.println("Create SimpleStandard MBean");