Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8344976: Remove the jmx.invoke.getters compatibility property #23132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 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
Expand Down Expand Up @@ -138,73 +138,20 @@ Object invoke(Object resource, String operation, Object[] params,
}

/*
* This method is called when invoke doesn't find the named method.
* Before throwing an exception, we check to see whether the
* jmx.invoke.getters property is set, and if so whether the method
* being invoked might be a getter or a setter. If so we invoke it
* and return the result. This is for compatibility
* with code based on JMX RI 1.0 or 1.1 which allowed invoking getters
* and setters. It is *not* recommended that new code use this feature.
*
* Since this method is either going to throw an exception or use
* functionality that is strongly discouraged, we consider that its
* performance is not very important.
*
* A simpler way to implement the functionality would be to add the getters
* and setters to the operations map when jmx.invoke.getters is set.
* However, that means that the property is consulted when an MBean
* interface is being introspected and not thereafter. Previously,
* the property was consulted on every invocation. So this simpler
* implementation could potentially break code that sets and unsets
* the property at different times.
* This method is called to throw an Exception when invoke doesn't find the named method.
*/
@SuppressWarnings("removal")
private Object noSuchMethod(String msg, Object resource, String operation,
Object[] params, String[] signature,
Object cookie)
throws MBeanException, ReflectionException {

// Construct the exception that we will probably throw
// Construct the exception that we will throw
final NoSuchMethodException nsme =
new NoSuchMethodException(operation + sigString(signature));
final ReflectionException exception =
new ReflectionException(nsme, msg);

if (introspector.isMXBean())
throw exception; // No compatibility requirement here

// Is the compatibility property set?
String invokeGettersS = System.getProperty("jmx.invoke.getters");
if (invokeGettersS == null)
throw exception;

int rest = 0;
Map<String, M> methods = null;
if (signature == null || signature.length == 0) {
if (operation.startsWith("get"))
rest = 3;
else if (operation.startsWith("is"))
rest = 2;
if (rest != 0)
methods = getters;
} else if (signature.length == 1 &&
operation.startsWith("set")) {
rest = 3;
methods = setters;
}

if (rest != 0) {
String attrName = operation.substring(rest);
M method = methods.get(attrName);
if (method != null && introspector.getName(method).equals(operation)) {
String[] msig = introspector.getSignature(method);
if ((signature == null && msig.length == 0) ||
Arrays.equals(signature, msig)) {
return introspector.invokeM(method, resource, params, cookie);
}
}
}

throw exception;
}

Expand Down
13 changes: 5 additions & 8 deletions test/jdk/javax/management/Introspector/InvokeGettersTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
* 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
Expand All @@ -23,8 +23,8 @@

/*
* @test
* @bug 6317101
* @summary Test that the jmx.invoke.getters system property works
* @bug 6317101 8344976
* @summary Test invocation after removal of the jmx.invoke.getters system property
* @author Eamonn McManus
*
* @run clean InvokeGettersTest
Expand Down Expand Up @@ -63,10 +63,7 @@ public static void main(String[] args) throws Exception {
ObjectName on = new ObjectName("a:b=c");
mbs.registerMBean(new Thing(), on);
if (test(mbs, on, false))
System.out.println("OK: invoke without jmx.invoke.getters");
System.setProperty("jmx.invoke.getters", "true");
if (test(mbs, on, true))
System.out.println("OK: invoke with jmx.invoke.getters");
System.out.println("OK");
if (failure == null)
System.out.println("TEST PASSED");
else
Expand Down Expand Up @@ -117,7 +114,7 @@ private static boolean test(MBeanServer mbs, ObjectName on,
System.out.println("isTrue got expected exception: " + e);
}

// Following cases should fail whether or not jmx.invoke.getters is set
// Following cases should fail
final Object[][] badInvokes = {
{"isWhatsit", null, null},
{"getWhatsit", new Object[] {5}, new String[] {"int"}},
Expand Down