diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java index 8b7e319e1..7a5f950e6 100644 --- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java +++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java @@ -8700,7 +8700,7 @@ public class ArrayUtils { } if(index < 0 ){ - index = 0; + return defaultReturn; } return array[index]; diff --git a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java index 984184cbb..0121473cc 100644 --- a/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java @@ -5125,7 +5125,7 @@ public class ArrayUtilsTest { assertEquals("Test", ArrayUtils.get(array, 10, "Test")); //negative index - assertEquals("Hello World", ArrayUtils.get(array, -1)); + assertEquals("Default", ArrayUtils.get(array, -1, "Default")); } @Test