You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by na...@apache.org on 2021/01/15 22:13:34 UTC
[lucene-solr] branch branch_8_8 updated: LUCENE-9661: Fix deadlock
in TermsEnum.EMPTY
This is an automated email from the ASF dual-hosted git repository.
namgyu pushed a commit to branch branch_8_8
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8_8 by this push:
new d1eca63 LUCENE-9661: Fix deadlock in TermsEnum.EMPTY
d1eca63 is described below
commit d1eca6399131950c74de156a4fb564ba70bdfc86
Author: Namgyu Kim <na...@apache.org>
AuthorDate: Sat Jan 16 06:49:23 2021 +0900
LUCENE-9661: Fix deadlock in TermsEnum.EMPTY
---
lucene/CHANGES.txt | 3 +
.../java/org/apache/lucene/index/TermsEnum.java | 127 ++++++++++++---------
2 files changed, 73 insertions(+), 57 deletions(-)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 08b3ff8..199d7e6 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -74,6 +74,9 @@ Bug Fixes
* LUCENE-9642: When encoding triangles in ShapeField, make sure generated triangles are CCW by rotating
triangle points before checking triangle orientation. (Ignacio Vera)
+* LUCENE-9661: Fix deadlock in TermsEnum.EMPTY that occurs when trying to initialize TermsEnum and BaseTermsEnum
+ at the same time (Namgyu Kim)
+
Other
---------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java b/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java
index 2cca1df..88c7167 100644
--- a/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java
+++ b/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java
@@ -188,62 +188,75 @@ public abstract class TermsEnum implements BytesRefIterator {
* This should not be a problem, as the enum is always empty and
* the existence of unused Attributes does not matter.
*/
- public static final TermsEnum EMPTY = new BaseTermsEnum() {
- @Override
- public SeekStatus seekCeil(BytesRef term) { return SeekStatus.END; }
-
- @Override
- public void seekExact(long ord) {}
-
- @Override
- public BytesRef term() {
- throw new IllegalStateException("this method should never be called");
- }
-
- @Override
- public int docFreq() {
- throw new IllegalStateException("this method should never be called");
- }
-
- @Override
- public long totalTermFreq() {
- throw new IllegalStateException("this method should never be called");
- }
-
- @Override
- public long ord() {
- throw new IllegalStateException("this method should never be called");
- }
-
- @Override
- public PostingsEnum postings(PostingsEnum reuse, int flags) {
- throw new IllegalStateException("this method should never be called");
- }
-
- @Override
- public ImpactsEnum impacts(int flags) throws IOException {
- throw new IllegalStateException("this method should never be called");
- }
-
- @Override
- public BytesRef next() {
- return null;
- }
-
- @Override // make it synchronized here, to prevent double lazy init
- public synchronized AttributeSource attributes() {
- return super.attributes();
- }
-
- @Override
- public TermState termState() {
- throw new IllegalStateException("this method should never be called");
- }
-
- @Override
- public void seekExact(BytesRef term, TermState state) {
- throw new IllegalStateException("this method should never be called");
- }
+ public static final TermsEnum EMPTY =
+ new TermsEnum() {
- };
+ private AttributeSource atts = null;
+
+ @Override
+ public SeekStatus seekCeil(BytesRef term) {
+ return SeekStatus.END;
+ }
+
+ @Override
+ public void seekExact(long ord) {}
+
+ @Override
+ public BytesRef term() {
+ throw new IllegalStateException("this method should never be called");
+ }
+
+ @Override
+ public int docFreq() {
+ throw new IllegalStateException("this method should never be called");
+ }
+
+ @Override
+ public long totalTermFreq() {
+ throw new IllegalStateException("this method should never be called");
+ }
+
+ @Override
+ public long ord() {
+ throw new IllegalStateException("this method should never be called");
+ }
+
+ @Override
+ public PostingsEnum postings(PostingsEnum reuse, int flags) {
+ throw new IllegalStateException("this method should never be called");
+ }
+
+ @Override
+ public ImpactsEnum impacts(int flags) throws IOException {
+ throw new IllegalStateException("this method should never be called");
+ }
+
+ @Override
+ public BytesRef next() {
+ return null;
+ }
+
+ @Override // make it synchronized here, to prevent double lazy init
+ public synchronized AttributeSource attributes() {
+ if (atts == null) {
+ atts = new AttributeSource();
+ }
+ return atts;
+ }
+
+ @Override
+ public boolean seekExact(BytesRef text) throws IOException {
+ return seekCeil(text) == SeekStatus.FOUND;
+ }
+
+ @Override
+ public TermState termState() {
+ throw new IllegalStateException("this method should never be called");
+ }
+
+ @Override
+ public void seekExact(BytesRef term, TermState state) {
+ throw new IllegalStateException("this method should never be called");
+ }
+ };
}