Closed Marcono1234 closed 3 years ago
@shannah thanks! Sorry I overlooked that there were setters for coerceInputs
and coerceOutputs
. Hopefully this change does not break existing code which only set one of them to false
.
I have commented on your commit, could you please have a look?
Edit: Sorry, had another look at it and maybe the lazy initialization is not worth it in the first place, I have omitted it in #35.
The static methods
Client.getInstance()
andgetRawClient()
do not perform safe lazy initialization: https://github.com/shannah/Java-Objective-C-Bridge/blob/473221aeef8f12ca9a659d899f3ca7092aed27ef/src/main/java/ca/weblite/objc/Client.java#L46-L51To correct this perform these steps:
instance
andrawClient
volatileinstance == null
(for increased performance store current value in local var)null
:instance == null
(and overwrite local var, see 2.1)null
: Initialize (and update local var, see 2.1)instance
(or local var) valueE.g.:
Or alternatively making these methods
synchronized
would also suffice and the performance decrease (if any) would likely be negligible. See also "LCK10-J. Use a correct form of the double-checked locking idiom"For sanity I would also recommend:
private
constructor, currentlyClient
has the public default constructorcoerceInputs
andcoerceOutputs
final
and initializing them from the constructor