commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <>
Subject [Commons Wiki] Update of "CodeStyle" by sebbapache
Date Mon, 13 Feb 2017 12:49:07 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Commons Wiki" for change notification.

The "CodeStyle" page has been changed by sebbapache:

   1. Mutable data: this increases the difficulty of ensuring thread-safety (including safe
publication of changes). Data should be confined to a class; mutation should only be allowed
via a setter which can ensure thread-safety. Be careful that the getter does not expose array
contents (which are always mutable)
   1. Even constants can cause problems: the Java compiler can inline constant values from
another class. So if the constant should ever change, classes that are not recompiled could
contain the old value.
   1. Array entries are always mutable. Only empty arrays are immutable; they can be safely
+  1. If a reference to a mutable object is exposed via a getter, then it can be modified
in a way that breaks thread-safety.
+  1. If a mutable object is saved by a setter and the caller keeps a reference to the object
then it can be changed without using the setter, bypassing any restrictions the setter would
have enforced.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message