Skip to content

Apache Lucene open-source search software

LUCENE-10583: Add docstring warning to not lock on Lucene objects (#963)

Vigya Sharma25a842d87198
diff --git a/lucene/core/src/java/org/apache/lucene/store/Directory.java b/lucene/core/src/java/org/apache/lucene/store/Directory.java
index bacf2d1681b..a94b906e22a 100644
--- a/lucene/core/src/java/org/apache/lucene/store/Directory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/Directory.java
@@ -40,6 +40,10 @@ import org.apache.lucene.util.IOUtils;
* java.nio.file.FileAlreadyExistsException}.
* </ul>
*
+ * <p><b>NOTE:</b> If your application requires external synchronization, you should <b>not</b>
+ * synchronize on the <code>Directory</code> implementation instance as this may cause deadlock; use
+ * your own (non-Lucene) objects instead.
+ *
* @see FSDirectory
* @see ByteBuffersDirectory
* @see FilterDirectory
diff --git a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
index f31a3a1f880..fa2dd16385e 100644
--- a/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
+++ b/lucene/core/src/java/org/apache/lucene/store/MMapDirectory.java
@@ -77,6 +77,10 @@ import org.apache.lucene.util.SuppressForbidden;
* Thread#interrupt()} or {@link Future#cancel(boolean)} you should use the legacy {@code
* RAFDirectory} from the Lucene {@code misc} module in favor of {@link MMapDirectory}.
*
+ * <p><b>NOTE:</b> If your application requires external synchronization, you should <b>not</b>
+ * synchronize on the <code>MMapDirectory</code> instance as this may cause deadlock; use your own
+ * (non-Lucene) objects instead.
+ *
* @see <a href="http://blog.thetaphi.de/2012/07/use-lucenes-mmapdirectory-on-64bit.html">Blog post
* about MMapDirectory</a>
*/