dweiss commented on code in PR #12199: URL: https://github.com/apache/lucene/pull/12199#discussion_r1132698882
########## lucene/core/src/java/org/apache/lucene/index/DocumentsWriterPerThreadPool.java: ########## @@ -113,15 +113,19 @@ private synchronized DocumentsWriterPerThread newWriter() { * operation (add/updateDocument). */ DocumentsWriterPerThread getAndLock() { - synchronized (this) { - ensureOpen(); - DocumentsWriterPerThread dwpt = freeList.poll(DocumentsWriterPerThread::tryLock); - if (dwpt == null) { - dwpt = newWriter(); + ensureOpen(); + DocumentsWriterPerThread dwpt = freeList.poll(DocumentsWriterPerThread::tryLock); + if (dwpt == null) { Review Comment: It's not about the poll. It's about whether dwpt = newWriter(); can be expanded and reordered by the compiler so that dwpt gets assigned a value before the constructor (or whatever initialization inside newWriter) takes place. Any thread checking dwpt == null outside synchronized could, at least in theory, see such a "partially constructed" object. -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org