1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* 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,
108
108
final List <MethodAndSig > list = ops .get (operation );
109
109
if (list == null ) {
110
110
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 );
113
112
}
114
113
if (signature == null )
115
114
signature = new String [0 ];
@@ -131,83 +130,11 @@ Object invoke(Object resource, String operation, Object[] params,
131
130
msg = "Operation " + operation + " exists but not with " +
132
131
"this signature: " + badSig ;
133
132
}
134
- return noSuchMethod (msg , resource , operation , params , signature ,
135
- cookie );
133
+ throw new ReflectionException (new NoSuchMethodException (operation + badSig ), msg );
136
134
}
137
135
return introspector .invokeM (found .method , resource , params , cookie );
138
136
}
139
137
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
-
211
138
private String sigString (String [] signature ) {
212
139
StringBuilder b = new StringBuilder ("(" );
213
140
if (signature != null ) {
1 commit comments
openjdk-notifier[bot] commentedon Jan 28, 2025
Review
Issues