LUCENE-9661: Fix deadlock in TermsEnum.EMPTY

This commit is contained in:
Namgyu Kim 2021-01-16 06:49:23 +09:00 committed by GitHub
parent 30aa0f5ba4
commit eb24e95731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -298,6 +298,9 @@ Bug Fixes
* LUCENE-9642: When encoding triangles in ShapeField, make sure generated triangles are CCW by rotating * LUCENE-9642: When encoding triangles in ShapeField, make sure generated triangles are CCW by rotating
triangle points before checking triangle orientation. (Ignacio Vera) 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 Other
--------------------- ---------------------

View File

@ -180,7 +180,10 @@ public abstract class TermsEnum implements BytesRefIterator {
* of unused Attributes does not matter. * of unused Attributes does not matter.
*/ */
public static final TermsEnum EMPTY = public static final TermsEnum EMPTY =
new BaseTermsEnum() { new TermsEnum() {
private AttributeSource atts = null;
@Override @Override
public SeekStatus seekCeil(BytesRef term) { public SeekStatus seekCeil(BytesRef term) {
return SeekStatus.END; return SeekStatus.END;
@ -226,7 +229,15 @@ public abstract class TermsEnum implements BytesRefIterator {
@Override // make it synchronized here, to prevent double lazy init @Override // make it synchronized here, to prevent double lazy init
public synchronized AttributeSource attributes() { 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 @Override