...
Compliant Solution
Wiki Markup |
---|
UseThis compliant solution uses the Builder pattern's \[[Gamma 95|AA. Java References#Gamma 95]\] variant suggested by Bloch \[[Bloch 08|AA. Java References#Bloch 08]\] to ensure thread safety and atomicity of object creation. |
...
If input needs to be validated, make sure that the values are copied from the builder class to the containing class's fields prior to checking. The builder class does not violate SCP03-J. Do not expose sensitive private members of the outer class from within a nested class because it maintains a copy of the variables defined in the scope of the containing class. These take precedence and as a result do not break encapsulation.
If the number of fields is small, it is better to synchronize the setter methods instead.
Risk Assessment
Using thread-unsafe implementations of method chaining can lead to undefined behavior.
...