Apache Solr open-source search software
LUCENE-9661: Fix deadlock in TermsEnum.EMPTY
Namgyu Kimeb24e95731b9
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex dfb4efa964e..7affde9e8c2 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -298,6 +298,9 @@ Bug Fixes* LUCENE-9642: When encoding triangles in ShapeField, make sure generated triangles are CCW by rotatingtriangle 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.javaindex 0f03c94a60b..de0234be908 100644--- a/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java+++ b/lucene/core/src/java/org/apache/lucene/index/TermsEnum.java@@ -180,7 +180,10 @@ public abstract class TermsEnum implements BytesRefIterator {* of unused Attributes does not matter.*/public static final TermsEnum EMPTY =- new BaseTermsEnum() {+ new TermsEnum() {++ private AttributeSource atts = null;+@Overridepublic SeekStatus seekCeil(BytesRef term) {return SeekStatus.END;@@ -226,7 +229,15 @@ public abstract class TermsEnum implements BytesRefIterator {@Override // make it synchronized here, to prevent double lazy initpublic synchronized AttributeSource attributes() {- return super.attributes();+ if (atts == null) {+ atts = new AttributeSource();+ }+ return atts;+ }++ @Override+ public boolean seekExact(BytesRef text) throws IOException {+ return seekCeil(text) == SeekStatus.FOUND;}@Override