jPOS icon indicating copy to clipboard operation
jPOS copied to clipboard

ChannelAdaptor potentially unsafe synchronization

Open agustiza opened this issue 1 year ago • 2 comments

Hello everyone,

Skimming through ChannelAdaptor source it seems in this line the disconnectLock is the shared Boolean.TRUE object.

This might be unsafe as someone might inadvertly deadlock the shutdown of a ChannelAdaptor by locking on Boolean.True. Also this would make the lock static in scope given that this lock instance would be shared among all other ChannelAdaptors.

Finally synchronizing against Boolean is warned against by the Java spec as Boolean and a few other java.lang classes are considered ValueBased classes. (See @jdk.internal.ValueBased)

A program may produce unpredictable results if it attempts to distinguish two references to equal values of a value-based class, whether directly via reference equality or indirectly via an appeal to synchronization, identity hashing, serialization, or any other identity-sensitive mechanism

Seems it could be swapped for new Object() without any side effect as far as I could see.

Probably never harmed anyone but better be safe!

Cheers

agustiza avatar Mar 11 '24 20:03 agustiza