3434import javax .management .MBeanOperationInfo ;
3535import javax .management .MalformedObjectNameException ;
3636import javax .management .ObjectName ;
37- import org .jspecify .annotations .Nullable ;
3837
3938public class MBean implements DynamicMBean {
4039
@@ -58,7 +57,7 @@ private static class AttributeInfo {
5857 this .setter = setter ;
5958 }
6059
61- @ Nullable
60+ @ SuppressWarnings ( "NullAway" )
6261 MBeanAttributeInfo getMBeanAttributeInfo () {
6362 try {
6463 return new MBeanAttributeInfo (name , description , getter , setter );
@@ -118,27 +117,22 @@ private void collectAttributeInfo(Object bean) {
118117 .forEach (ai -> attributeMap .put (ai .name , ai ));
119118 }
120119
121- @ Nullable
120+ @ SuppressWarnings ( "NullAway" )
122121 private AttributeInfo getAttributeInfo (Method m ) {
123122 ManagedAttribute ma = m .getAnnotation (ManagedAttribute .class );
124123 if (ma == null ) {
125124 return null ;
126125 }
127126 try {
128127 String name = "" .equals (ma .name ()) ? m .getName () : ma .name ();
129- Method getter = findGetter (m );
130- Method setter = findSetter (m );
131- if (getter == null || setter == null ) {
132- return null ;
133- }
134- return new AttributeInfo (name , ma .description (), getter , setter );
128+ return new AttributeInfo (name , ma .description (), findGetter (m ), findSetter (m ));
135129 } catch (Throwable t ) {
136130 LOG .severe ("Error during execution: " + t .getMessage ());
137131 return null ;
138132 }
139133 }
140134
141- @ Nullable
135+ @ SuppressWarnings ( "NullAway" )
142136 private Method findGetter (Method annotatedMethod ) {
143137 ManagedAttribute ma = annotatedMethod .getAnnotation (ManagedAttribute .class );
144138 try {
@@ -160,7 +154,7 @@ private Method findGetter(Method annotatedMethod) {
160154 }
161155 }
162156
163- @ Nullable
157+ @ SuppressWarnings ( "NullAway" )
164158 private Method findSetter (Method annotatedMethod ) {
165159 ManagedAttribute ma = annotatedMethod .getAnnotation (ManagedAttribute .class );
166160 if (!"" .equals (ma .setter ())) {
@@ -180,7 +174,7 @@ private Method findSetter(Method annotatedMethod) {
180174 return null ;
181175 }
182176
183- @ Nullable
177+ @ SuppressWarnings ( "NullAway" )
184178 private Method findMethod (Class <?> cls , String name ) {
185179 return Stream .of (cls .getMethods ())
186180 .filter (m -> m .getName ().equals (name ))
@@ -195,7 +189,7 @@ private void collectOperationInfo(Object bean) {
195189 .forEach (oi -> operationMap .put (oi .name , oi ));
196190 }
197191
198- @ Nullable
192+ @ SuppressWarnings ( "NullAway" )
199193 private OperationInfo getOperationInfo (Method m ) {
200194 ManagedOperation mo = m .getAnnotation (ManagedOperation .class );
201195 if (mo == null ) {
@@ -225,15 +219,11 @@ private ObjectName generateObjectName(Object bean) {
225219 }
226220 }
227221
228- @ Nullable
222+ @ SuppressWarnings ( "NullAway" )
229223 @ Override
230224 public Object getAttribute (String attribute ) {
231- AttributeInfo attributeInfo = attributeMap .get (attribute );
232- if (attributeInfo == null ) {
233- return null ;
234- }
235225 try {
236- Object res = attributeInfo .getter .invoke (bean );
226+ Object res = attributeMap . get ( attribute ) .getter .invoke (bean );
237227 if (res instanceof Map <?, ?>) {
238228 return ((Map <?, ?>) res )
239229 .entrySet ().stream ()
@@ -249,14 +239,11 @@ public Object getAttribute(String attribute) {
249239 }
250240 }
251241
242+ @ SuppressWarnings ("NullAway" )
252243 @ Override
253244 public void setAttribute (Attribute attribute ) {
254- AttributeInfo attributeInfo = attributeMap .get (attribute .getName ());
255- if (attributeInfo == null ) {
256- return ;
257- }
258245 try {
259- attributeInfo .setter .invoke (bean , attribute .getValue ());
246+ attributeMap . get ( attribute . getName ()) .setter .invoke (bean , attribute .getValue ());
260247 } catch (IllegalAccessException | InvocationTargetException e ) {
261248 LOG .severe ("Error during execution: " + e .getMessage ());
262249 }
@@ -277,21 +264,17 @@ public AttributeList getAttributes(String[] attributes) {
277264 return resultList ;
278265 }
279266
280- @ Nullable
267+ @ SuppressWarnings ( "NullAway" )
281268 @ Override
282269 public AttributeList setAttributes (AttributeList attributes ) {
283270 return null ;
284271 }
285272
286- @ Nullable
273+ @ SuppressWarnings ( "NullAway" )
287274 @ Override
288275 public Object invoke (String actionName , Object [] params , String [] signature ) {
289- OperationInfo operationInfo = operationMap .get (actionName );
290- if (operationInfo == null ) {
291- return null ;
292- }
293276 try {
294- return operationInfo .method .invoke (bean , params );
277+ return operationMap . get ( actionName ) .method .invoke (bean , params );
295278 } catch (IllegalAccessException | InvocationTargetException e ) {
296279 LOG .severe ("Error during execution: " + e .getMessage ());
297280 return null ;
0 commit comments