nfsantos commented on PR #2457: URL: https://github.com/apache/jackrabbit-oak/pull/2457#issuecomment-3204267456
Hmm... I think I understand why it might be incorrect, but I don't see why the return would fix this. Scenario: - Thread 1 enters the synchronized block and executes up to `initialized = true`. It is suspended at this point - Thread 2 enters the method and sees `initialized = true` because this variable is volatile. However, `result` is not volatile so we have no guarantees that it will be updated until thread 1 leaves the synchronized block. - Thread 3 skips the initialization block and returns result, which is still null. I believe this can happen, but returning from within the block will not prevent this from happening. Unless there's something about putting the return there that makes it more likely that thread 1 will leave the synchronized block faster. Or maybe non-determinism in the tests. The solution with AtomicReference should not have the problem described above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org