hypfvieh / dbus-java

Improved version of java DBus library provided by freedesktop.org (https://dbus.freedesktop.org/doc/dbus-java/)
https://hypfvieh.github.io/dbus-java/
MIT License
185 stars 73 forks source link

Superfluous executors check #189

Closed ghost closed 2 years ago

ghost commented 2 years ago

Is the check for null superfluous?

https://github.com/hypfvieh/dbus-java/blob/deeda69cba75aa25b47e047ce59aa7403677a1e8/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/ReceivingService.java#L154

Because the map is final?

https://github.com/hypfvieh/dbus-java/blob/deeda69cba75aa25b47e047ce59aa7403677a1e8/dbus-java-core/src/main/java/org/freedesktop/dbus/connections/ReceivingService.java#L31

Also, without the final there's a potential race-condition if executors could have ever been set to null (or could do so in future versions) in a multi-threaded environment. Simply returning is less confusing/misleading. If you want to ensure there's no null, how about adding an assert that gets optimized away when building a production version?

        assert executors != null;
        return executors.get(_executor);