|
40 | 40 | import java.util.List; |
41 | 41 | import java.util.Map; |
42 | 42 | import java.util.Objects; |
| 43 | +import java.util.Optional; |
43 | 44 | import java.util.Set; |
44 | 45 | import java.util.function.BiConsumer; |
45 | 46 | import java.util.stream.Collectors; |
@@ -202,7 +203,7 @@ public <T> T getFieldValue(String path, Class<T> clazz) { |
202 | 203 | * or if the field that is found at the provided path is not of the expected type. |
203 | 204 | */ |
204 | 205 | public <T> T getFieldValue(String path, Class<T> clazz, boolean ignoreMissing) { |
205 | | - final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPattern()); |
| 206 | + final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPatternSafe()); |
206 | 207 | Object context = fieldPath.initialContext(this); |
207 | 208 | ResolveResult result = resolve(fieldPath.pathElements, fieldPath.pathElements.length, path, context, getCurrentAccessPatternSafe()); |
208 | 209 | if (result.wasSuccessful) { |
@@ -271,7 +272,7 @@ public boolean hasField(String path) { |
271 | 272 | * @throws IllegalArgumentException if the path is null, empty or invalid. |
272 | 273 | */ |
273 | 274 | public boolean hasField(String path, boolean failOutOfRange) { |
274 | | - final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPattern()); |
| 275 | + final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPatternSafe()); |
275 | 276 | Object context = fieldPath.initialContext(this); |
276 | 277 | int leafKeyIndex = fieldPath.pathElements.length - 1; |
277 | 278 | int lastContainerIndex = fieldPath.pathElements.length - 2; |
@@ -425,7 +426,7 @@ public void removeField(String path) { |
425 | 426 | * @throws IllegalArgumentException if the path is null, empty, or invalid; or if the field doesn't exist (and ignoreMissing is false). |
426 | 427 | */ |
427 | 428 | public void removeField(String path, boolean ignoreMissing) { |
428 | | - final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPattern()); |
| 429 | + final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPatternSafe()); |
429 | 430 | Object context = fieldPath.initialContext(this); |
430 | 431 | String leafKey = fieldPath.pathElements[fieldPath.pathElements.length - 1]; |
431 | 432 | ResolveResult result = resolve( |
@@ -735,7 +736,7 @@ public void setFieldValue(String path, Object value, boolean ignoreEmptyValue) { |
735 | 736 | } |
736 | 737 |
|
737 | 738 | private void setFieldValue(String path, Object value, boolean append, boolean allowDuplicates) { |
738 | | - final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPattern()); |
| 739 | + final FieldPath fieldPath = FieldPath.of(path, getCurrentAccessPatternSafe()); |
739 | 740 | Object context = fieldPath.initialContext(this); |
740 | 741 | int leafKeyIndex = fieldPath.pathElements.length - 1; |
741 | 742 | int lastContainerIndex = fieldPath.pathElements.length - 2; |
@@ -1154,18 +1155,18 @@ List<String> getPipelineStack() { |
1154 | 1155 | } |
1155 | 1156 |
|
1156 | 1157 | /** |
1157 | | - * @return The access pattern for any currently executing pipelines, or null if no pipelines are in progress for this doc |
| 1158 | + * @return The access pattern for any currently executing pipelines, or empty if no pipelines are in progress for this doc |
1158 | 1159 | */ |
1159 | | - public IngestPipelineFieldAccessPattern getCurrentAccessPattern() { |
1160 | | - return accessPatternStack.peek(); |
| 1160 | + public Optional<IngestPipelineFieldAccessPattern> getCurrentAccessPattern() { |
| 1161 | + return Optional.ofNullable(accessPatternStack.peek()); |
1161 | 1162 | } |
1162 | 1163 |
|
1163 | 1164 | /** |
1164 | 1165 | * @return The access pattern for any currently executing pipelines, or {@link IngestPipelineFieldAccessPattern#CLASSIC} if no |
1165 | 1166 | * pipelines are in progress for this doc for the sake of backwards compatibility |
1166 | 1167 | */ |
1167 | 1168 | private IngestPipelineFieldAccessPattern getCurrentAccessPatternSafe() { |
1168 | | - return Objects.requireNonNullElse(getCurrentAccessPattern(), IngestPipelineFieldAccessPattern.CLASSIC); |
| 1169 | + return getCurrentAccessPattern().orElse(IngestPipelineFieldAccessPattern.CLASSIC); |
1169 | 1170 | } |
1170 | 1171 |
|
1171 | 1172 | /** |
|
0 commit comments