Repository: nifi Updated Branches: refs/heads/master 7f8987471 -> 1a3c525dd
NIFI-3951: Fixed bug that calculated the index incorrectly when filtering for ArrayIndexPath This closes #1835. Signed-off-by: Bryan Bende <bbe...@apache.org> Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/1a3c525d Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/1a3c525d Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/1a3c525d Branch: refs/heads/master Commit: 1a3c525dd68d7ad5403a23aaabda131edbf489fa Parents: 7f89874 Author: Mark Payne <marka...@hotmail.com> Authored: Mon May 22 09:45:35 2017 -0400 Committer: Bryan Bende <bbe...@apache.org> Committed: Mon May 22 12:39:32 2017 -0400 ---------------------------------------------------------------------- .../org/apache/nifi/record/path/paths/ArrayIndexPath.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/1a3c525d/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/ArrayIndexPath.java ---------------------------------------------------------------------- diff --git a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/ArrayIndexPath.java b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/ArrayIndexPath.java index 287ae2d..3e81868 100644 --- a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/ArrayIndexPath.java +++ b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/ArrayIndexPath.java @@ -42,16 +42,20 @@ public class ArrayIndexPath extends RecordPathSegment { return parentResult .filter(Filters.fieldTypeFilter(RecordFieldType.ARRAY)) - .filter(fieldValue -> fieldValue.getValue() != null && ((Object[]) fieldValue.getValue()).length >= Math.abs(index) - 1) + .filter(fieldValue -> fieldValue.getValue() != null && ((Object[]) fieldValue.getValue()).length > getArrayIndex(((Object[]) fieldValue.getValue()).length)) .map(fieldValue -> { final ArrayDataType arrayDataType = (ArrayDataType) fieldValue.getField().getDataType(); final DataType elementDataType = arrayDataType.getElementType(); final RecordField arrayField = new RecordField(fieldValue.getField().getFieldName(), elementDataType); final Object[] values = (Object[]) fieldValue.getValue(); - final int arrayIndex = index < 0 ? values.length + index : index; + final int arrayIndex = getArrayIndex(values.length); final RecordField elementField = new RecordField(arrayField.getFieldName() + "[" + arrayIndex + "]", elementDataType); final FieldValue result = new ArrayIndexFieldValue(values[arrayIndex], elementField, fieldValue, arrayIndex); return result; }); } + + private int getArrayIndex(final int arrayLength) { + return index < 0 ? arrayLength + index : index; + } }