Skip to content

Commit f71541c

Browse files
committedJan 28, 2025
8344976: Remove the jmx.invoke.getters compatibility property
Reviewed-by: cjplummer, dfuchs, sspitsyn
1 parent 2537a05 commit f71541c

File tree

2 files changed

+8
-84
lines changed

2 files changed

+8
-84
lines changed
 

‎src/java.management/share/classes/com/sun/jmx/mbeanserver/PerInterface.java

+3-76
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -108,8 +108,7 @@ Object invoke(Object resource, String operation, Object[] params,
108108
final List<MethodAndSig> list = ops.get(operation);
109109
if (list == null) {
110110
final String msg = "No such operation: " + operation;
111-
return noSuchMethod(msg, resource, operation, params, signature,
112-
cookie);
111+
throw new ReflectionException(new NoSuchMethodException(operation + sigString(signature)), msg);
113112
}
114113
if (signature == null)
115114
signature = new String[0];
@@ -131,83 +130,11 @@ Object invoke(Object resource, String operation, Object[] params,
131130
msg = "Operation " + operation + " exists but not with " +
132131
"this signature: " + badSig;
133132
}
134-
return noSuchMethod(msg, resource, operation, params, signature,
135-
cookie);
133+
throw new ReflectionException(new NoSuchMethodException(operation + badSig), msg);
136134
}
137135
return introspector.invokeM(found.method, resource, params, cookie);
138136
}
139137

140-
/*
141-
* This method is called when invoke doesn't find the named method.
142-
* Before throwing an exception, we check to see whether the
143-
* jmx.invoke.getters property is set, and if so whether the method
144-
* being invoked might be a getter or a setter. If so we invoke it
145-
* and return the result. This is for compatibility
146-
* with code based on JMX RI 1.0 or 1.1 which allowed invoking getters
147-
* and setters. It is *not* recommended that new code use this feature.
148-
*
149-
* Since this method is either going to throw an exception or use
150-
* functionality that is strongly discouraged, we consider that its
151-
* performance is not very important.
152-
*
153-
* A simpler way to implement the functionality would be to add the getters
154-
* and setters to the operations map when jmx.invoke.getters is set.
155-
* However, that means that the property is consulted when an MBean
156-
* interface is being introspected and not thereafter. Previously,
157-
* the property was consulted on every invocation. So this simpler
158-
* implementation could potentially break code that sets and unsets
159-
* the property at different times.
160-
*/
161-
@SuppressWarnings("removal")
162-
private Object noSuchMethod(String msg, Object resource, String operation,
163-
Object[] params, String[] signature,
164-
Object cookie)
165-
throws MBeanException, ReflectionException {
166-
167-
// Construct the exception that we will probably throw
168-
final NoSuchMethodException nsme =
169-
new NoSuchMethodException(operation + sigString(signature));
170-
final ReflectionException exception =
171-
new ReflectionException(nsme, msg);
172-
173-
if (introspector.isMXBean())
174-
throw exception; // No compatibility requirement here
175-
176-
// Is the compatibility property set?
177-
String invokeGettersS = System.getProperty("jmx.invoke.getters");
178-
if (invokeGettersS == null)
179-
throw exception;
180-
181-
int rest = 0;
182-
Map<String, M> methods = null;
183-
if (signature == null || signature.length == 0) {
184-
if (operation.startsWith("get"))
185-
rest = 3;
186-
else if (operation.startsWith("is"))
187-
rest = 2;
188-
if (rest != 0)
189-
methods = getters;
190-
} else if (signature.length == 1 &&
191-
operation.startsWith("set")) {
192-
rest = 3;
193-
methods = setters;
194-
}
195-
196-
if (rest != 0) {
197-
String attrName = operation.substring(rest);
198-
M method = methods.get(attrName);
199-
if (method != null && introspector.getName(method).equals(operation)) {
200-
String[] msig = introspector.getSignature(method);
201-
if ((signature == null && msig.length == 0) ||
202-
Arrays.equals(signature, msig)) {
203-
return introspector.invokeM(method, resource, params, cookie);
204-
}
205-
}
206-
}
207-
208-
throw exception;
209-
}
210-
211138
private String sigString(String[] signature) {
212139
StringBuilder b = new StringBuilder("(");
213140
if (signature != null) {

‎test/jdk/javax/management/Introspector/InvokeGettersTest.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -23,8 +23,8 @@
2323

2424
/*
2525
* @test
26-
* @bug 6317101
27-
* @summary Test that the jmx.invoke.getters system property works
26+
* @bug 6317101 8344976
27+
* @summary Test invocation after removal of the jmx.invoke.getters system property
2828
* @author Eamonn McManus
2929
*
3030
* @run clean InvokeGettersTest
@@ -63,10 +63,7 @@ public static void main(String[] args) throws Exception {
6363
ObjectName on = new ObjectName("a:b=c");
6464
mbs.registerMBean(new Thing(), on);
6565
if (test(mbs, on, false))
66-
System.out.println("OK: invoke without jmx.invoke.getters");
67-
System.setProperty("jmx.invoke.getters", "true");
68-
if (test(mbs, on, true))
69-
System.out.println("OK: invoke with jmx.invoke.getters");
66+
System.out.println("OK");
7067
if (failure == null)
7168
System.out.println("TEST PASSED");
7269
else
@@ -117,7 +114,7 @@ private static boolean test(MBeanServer mbs, ObjectName on,
117114
System.out.println("isTrue got expected exception: " + e);
118115
}
119116

120-
// Following cases should fail whether or not jmx.invoke.getters is set
117+
// Following cases should fail
121118
final Object[][] badInvokes = {
122119
{"isWhatsit", null, null},
123120
{"getWhatsit", new Object[] {5}, new String[] {"int"}},

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jan 28, 2025

@openjdk-notifier[bot]
Please sign in to comment.