Skip to content

Commit 8e58c01

Browse files
authored
Fix watcher check that determines when to serialize indices options. (#78165)
Backporting #78070 to 7.x branch. The check was an identity check between the default constant and the set indices options. This check is incorrect because in many cases when `IndicesOptions` is parsed or randomly generated in tests, then this check incorrectly returns false when in fact an `IndicesOptions` instance is equal to the default constant, but it is just a different instance/object. Closes #78035
1 parent 67fb3b8 commit 8e58c01

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/search/WatcherSearchTemplateRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
158158
builder.rawField(BODY_FIELD.getPreferredName(), stream);
159159
}
160160
}
161-
if (indicesOptions != DEFAULT_INDICES_OPTIONS) {
161+
if (indicesOptions.equals(DEFAULT_INDICES_OPTIONS) == false) {
162162
builder.startObject(INDICES_OPTIONS_FIELD.getPreferredName());
163163
indicesOptions.toXContent(builder, params);
164164
builder.endObject();

x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherUtilsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ public void testSerializeSearchRequest() throws Exception {
150150
assertThat(result.getTemplate().getIdOrCode(), equalTo(expectedSource.utf8ToString()));
151151
assertThat(result.getTemplate().getType(), equalTo(ScriptType.INLINE));
152152
}
153-
if (expectedIndicesOptions != DEFAULT_INDICES_OPTIONS && expectedTypes != null) {
153+
if (expectedIndicesOptions.equals(DEFAULT_INDICES_OPTIONS) == false && expectedTypes != null) {
154154
assertWarnings(IGNORE_THROTTLED_FIELD_WARNING, WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);
155155
assertThat(result.getTypes(), arrayContainingInAnyOrder(expectedTypes));
156-
} else if (expectedIndicesOptions != DEFAULT_INDICES_OPTIONS) {
156+
} else if (expectedIndicesOptions.equals(DEFAULT_INDICES_OPTIONS) == false) {
157157
assertWarnings(IGNORE_THROTTLED_FIELD_WARNING);
158158
} else if (expectedTypes != null) {
159159
assertWarnings(WatcherSearchTemplateRequest.TYPES_DEPRECATION_MESSAGE);

0 commit comments

Comments
 (0)