You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@orc.apache.org by do...@apache.org on 2023/09/19 15:34:39 UTC
[orc] branch main updated: ORC-1504: Add lower bound check for get() in DynamicIntArray
This is an automated email from the ASF dual-hosted git repository.
dongjoon pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/orc.git
The following commit(s) were added to refs/heads/main by this push:
new f1d15a2b0 ORC-1504: Add lower bound check for get() in DynamicIntArray
f1d15a2b0 is described below
commit f1d15a2b04d536570383eba6e22227eb42ff8550
Author: mystic-lama <my...@gmail.com>
AuthorDate: Tue Sep 19 08:34:30 2023 -0700
ORC-1504: Add lower bound check for get() in DynamicIntArray
### What changes were proposed in this pull request?
The PR proposes adding check for lower bound for index passed to get() in DynamicIntArray
### Why are the changes needed?
In the absence of lower bound check, the code fails later with ArrayIndexOutOfBoundException. The code doesn't break, however the user behavior is different. This PR unifies the exception user gets, when the index is not in range
### How was this patch tested?
Unit Test case was enhanced to add the test to validate the scenario
Closes #1616 from mystic-lama/dynamicIntArray_bound_checks.
Authored-by: mystic-lama <my...@gmail.com>
Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
java/core/src/java/org/apache/orc/impl/DynamicIntArray.java | 2 +-
.../core/src/test/org/apache/orc/impl/TestDynamicIntArray.java | 10 +++++++++-
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java b/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java
index 74d8e79b9..3166fb7a1 100644
--- a/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java
+++ b/java/core/src/java/org/apache/orc/impl/DynamicIntArray.java
@@ -69,7 +69,7 @@ public final class DynamicIntArray {
}
public int get(int index) {
- if (index >= length) {
+ if (index < 0 || index >= length) {
throw new IndexOutOfBoundsException("Index " + index +
" is outside of 0.." +
(length - 1));
diff --git a/java/core/src/test/org/apache/orc/impl/TestDynamicIntArray.java b/java/core/src/test/org/apache/orc/impl/TestDynamicIntArray.java
index 2c0f882e0..cb21aa59b 100644
--- a/java/core/src/test/org/apache/orc/impl/TestDynamicIntArray.java
+++ b/java/core/src/test/org/apache/orc/impl/TestDynamicIntArray.java
@@ -75,6 +75,14 @@ public class TestDynamicIntArray {
public void testInvalidGetIndex() {
DynamicIntArray dynamicIntArray = new DynamicIntArray(10);
dynamicIntArray.add(10);
- assertThrows(IndexOutOfBoundsException.class, () -> dynamicIntArray.get(11));
+ dynamicIntArray.add(11);
+ IndexOutOfBoundsException indexOutOfBoundsException =
+ assertThrows(IndexOutOfBoundsException.class, () -> dynamicIntArray.get(11));
+ assertEquals("Index 11 is outside of 0..1", indexOutOfBoundsException.getMessage());
+
+ indexOutOfBoundsException =
+ assertThrows(IndexOutOfBoundsException.class, () -> dynamicIntArray.get(-1));
+ assertEquals("Index -1 is outside of 0..1", indexOutOfBoundsException.getMessage());
+
}
}