[java] JSpecify annotations for `org.openqa.selenium.grid.jmx` by mk868 · Pull Request #16431 · SeleniumHQ/selenium
PR Code Suggestions ✨
Explore these optional code suggestions:
| Category | Suggestion | Impact |
| Possible issue |
Return null on registration failureModify the java/src/org/openqa/selenium/grid/jmx/JMXHelper.java [36-44] try {
mbs.registerMBean(mBean, mBean.getObjectName());
return mBean;
} catch (InstanceAlreadyExistsException t) {
- return mBean;
+ LOG.warning("Could not register MBean: " + t.getMessage());
+ return null;
} catch (Throwable t) {
LOG.severe("Error during execution: " + t.getMessage());
return null;
}
Suggestion importance[1-10]: 7__ Why: The suggestion improves API consistency by proposing to return | Medium |
| General |
Clarify parameter nullability with an annotationAdd the java/src/org/openqa/selenium/grid/jmx/JMXHelper.java [47-55] -public void unregister(ObjectName objectName) { +public void unregister(@Nullable ObjectName objectName) { if (objectName != null) { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); try { mbs.unregisterMBean(objectName); } catch (Throwable ignore) { } } }
Suggestion importance[1-10]: 6__ Why: The suggestion correctly identifies an inconsistency between the newly added | Low |
| Learned best practice |
Add null check for inputAdd a null check for java/src/org/openqa/selenium/grid/jmx/JMXHelper.java [33-45] public @Nullable MBean register(Object bean) {
+ if (bean == null) {
+ throw new IllegalArgumentException("bean must not be null");
+ }
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
MBean mBean = new MBean(bean);
try {
mbs.registerMBean(mBean, mBean.getObjectName());
return mBean;
} catch (InstanceAlreadyExistsException t) {
return mBean;
} catch (Throwable t) {
LOG.severe("Error during execution: " + t.getMessage());
return null;
}
}
Suggestion importance[1-10]: 6__ Why: | Low |
| ||