You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2019/05/20 18:20:38 UTC
[lucene-solr] branch branch_8x updated: LUCENE-8804: Forbid calls
to putAttribute on frozen FieldType instances.
This is an automated email from the ASF dual-hosted git repository.
jpountz pushed a commit to branch branch_8x
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git
The following commit(s) were added to refs/heads/branch_8x by this push:
new 01d70ea LUCENE-8804: Forbid calls to putAttribute on frozen FieldType instances.
01d70ea is described below
commit 01d70ea4ca142f9302d7934cef52f7498b0dc007
Author: Adrien Grand <jp...@gmail.com>
AuthorDate: Mon May 20 17:23:49 2019 +0200
LUCENE-8804: Forbid calls to putAttribute on frozen FieldType instances.
---
lucene/CHANGES.txt | 3 +++
.../java/org/apache/lucene/document/FieldType.java | 1 +
.../org/apache/lucene/document/TestFieldType.java | 21 +++++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 361dea1..dcdb79b 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -11,6 +11,9 @@ Bug Fixes
This causes assertion errors and potentially broken field attributes in the IndexWriter when
IndexWriter#deleteAll is called while actively indexing. (Simon Willnauer)
+* LUCENE-8804: Forbid calls to putAttribute on frozen FieldType instances.
+ (Vamshi Vijay Nakkirtha via Adrien Grand)
+
Improvements
* LUCENE-7840: Non-scoring BooleanQuery now removes SHOULD clauses before building the scorer supplier
diff --git a/lucene/core/src/java/org/apache/lucene/document/FieldType.java b/lucene/core/src/java/org/apache/lucene/document/FieldType.java
index b450eee..8dd802c 100644
--- a/lucene/core/src/java/org/apache/lucene/document/FieldType.java
+++ b/lucene/core/src/java/org/apache/lucene/document/FieldType.java
@@ -361,6 +361,7 @@ public class FieldType implements IndexableFieldType {
* @lucene.experimental
*/
public String putAttribute(String key, String value) {
+ checkIfFrozen();
if (attributes == null) {
attributes = new HashMap<>();
}
diff --git a/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
index b770e62..8237a4f 100644
--- a/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
+++ b/lucene/core/src/test/org/apache/lucene/document/TestFieldType.java
@@ -72,6 +72,27 @@ public class TestFieldType extends LuceneTestCase {
assertEquals("pointDataDimensionCount=1,pointIndexDimensionCount=1,pointNumBytes=4", ft.toString());
}
+ /**
+ * FieldType's attribute map should not be modifiable/add after freeze
+ */
+ public void testAttributeMapFrozen() {
+ FieldType ft = new FieldType();
+ ft.putAttribute("dummy", "d");
+ ft.freeze();
+ expectThrows(IllegalStateException.class, () -> ft.putAttribute("dummy", "a"));
+ }
+
+ /**
+ * FieldType's attribute map can be changed if not frozen
+ */
+ public void testAttributeMapNotFrozen() {
+ FieldType ft = new FieldType();
+ ft.putAttribute("dummy", "d");
+ ft.putAttribute("dummy", "a");
+ assertEquals(ft.getAttributes().size(), 1);
+ assertEquals(ft.getAttributes().get("dummy"), "a");
+ }
+
private static Object randomValue(Class<?> clazz) {
if (clazz.isEnum()) {
return RandomPicks.randomFrom(random(), clazz.getEnumConstants());