Buggy exception handling in ServerNotifForwarder#removeNotificationListener
Andrey Turbanov
turbanoff at gmail.com
Wed Aug 18 11:52:03 UTC 2021
Hello.
During investigation of IDEA inspections I found suspicious code in a method
com.sun.jmx.remote.internal.ServerNotifForwarder#removeNotificationListener
https://github.com/openjdk/jdk/blob/master/src/java.management/share/classes/com/sun/jmx/remote/internal/ServerNotifForwarder.java#L167
Exception re = null;
for (int i = 0 ; i < listenerIDs.length ; i++) {
try {
removeNotificationListener(name, listenerIDs[i]);
} catch (Exception e) {
// Give back the first exception
//
if (re != null) {
re = e;
}
}
}
if (re != null) {
throw re;
}
Variable 're' set initially to 'null', but then in a catch block it
checked to be '!= null'.
As you can see this condition can never be true. And exceptions from
inner calls are not propagated as expected.
It seems that it should check if (re == null) inside the catch block.
Andrey Turbanov
More information about the serviceability-dev
mailing list