From eb24e95731b9f865b95b821c1745264fdc58119d Mon Sep 17 00:00:00 2001 From: Namgyu Kim Date: Sat, 16 Jan 2021 06:49:23 +0900 Subject: [PATCH] LUCENE-9661: Fix deadlock in TermsEnum.EMPTY --- lucene/CHANGES.txt | 3 +++ .../java/org/apache/lucene/index/TermsEnum.java | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 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 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 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; + @Override public 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 init public 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