mirror of
https://github.com/apache/lucene.git
synced 2025-02-10 20:15:18 +00:00
LUCENE-8804: Forbid calls to putAttribute on frozen FieldType instances.
This commit is contained in:
parent
ed4b789bf4
commit
ec6ac9756c
@ -41,6 +41,9 @@ Bug Fixes
|
|||||||
This causes assertion errors and potentially broken field attributes in the IndexWriter when
|
This causes assertion errors and potentially broken field attributes in the IndexWriter when
|
||||||
IndexWriter#deleteAll is called while actively indexing. (Simon Willnauer)
|
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
|
Improvements
|
||||||
|
|
||||||
* LUCENE-7840: Non-scoring BooleanQuery now removes SHOULD clauses before building the scorer supplier
|
* LUCENE-7840: Non-scoring BooleanQuery now removes SHOULD clauses before building the scorer supplier
|
||||||
|
@ -361,6 +361,7 @@ public class FieldType implements IndexableFieldType {
|
|||||||
* @lucene.experimental
|
* @lucene.experimental
|
||||||
*/
|
*/
|
||||||
public String putAttribute(String key, String value) {
|
public String putAttribute(String key, String value) {
|
||||||
|
checkIfFrozen();
|
||||||
if (attributes == null) {
|
if (attributes == null) {
|
||||||
attributes = new HashMap<>();
|
attributes = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,27 @@ public class TestFieldType extends LuceneTestCase {
|
|||||||
assertEquals("pointDataDimensionCount=1,pointIndexDimensionCount=1,pointNumBytes=4", ft.toString());
|
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) {
|
private static Object randomValue(Class<?> clazz) {
|
||||||
if (clazz.isEnum()) {
|
if (clazz.isEnum()) {
|
||||||
return RandomPicks.randomFrom(random(), clazz.getEnumConstants());
|
return RandomPicks.randomFrom(random(), clazz.getEnumConstants());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user