Avoid failure when Monitors.registerMonitor is used with an anonymous class