diff --git a/Examples/test-suite/java/li_std_list_runme.java b/Examples/test-suite/java/li_std_list_runme.java index ea2227faf..e45b8968b 100644 --- a/Examples/test-suite/java/li_std_list_runme.java +++ b/Examples/test-suite/java/li_std_list_runme.java @@ -158,5 +158,23 @@ public class li_std_list_runme { if (v10.size() != 4) throw new RuntimeException("v10 test (4) failed"); if (v10.get(1) != 22) throw new RuntimeException("v10 test (5) failed"); if (v10.get(2) != 33) throw new RuntimeException("v10 test (6) failed"); + + v10.add(v10.size(), 55); + if (v10.size() != 5) throw new RuntimeException("v10 test (7) failed"); + if (v10.get(4) != 55) throw new RuntimeException("v10 test (8) failed"); + + IntList v11 = new IntList(java.util.Arrays.asList(11, 22, 33, 44)); + v11.listIterator(0); + v11.listIterator(v11.size()); + try { + v11.listIterator(v11.size() + 1); + throw new RuntimeException("v11 test (1) failed"); + } catch (IndexOutOfBoundsException e) { + } + try { + v11.listIterator(-1); + throw new RuntimeException("v11 test (2) failed"); + } catch (IndexOutOfBoundsException e) { + } } } diff --git a/Examples/test-suite/java/li_std_vector_runme.java b/Examples/test-suite/java/li_std_vector_runme.java index 5371a2ba2..d23bbe7cd 100644 --- a/Examples/test-suite/java/li_std_vector_runme.java +++ b/Examples/test-suite/java/li_std_vector_runme.java @@ -149,5 +149,23 @@ public class li_std_vector_runme { if (v10.size() != 4) throw new RuntimeException("v10 test (4) failed"); if (v10.get(1) != 22) throw new RuntimeException("v10 test (5) failed"); if (v10.get(2) != 33) throw new RuntimeException("v10 test (6) failed"); + + v10.add(v10.size(), 55); + if (v10.size() != 5) throw new RuntimeException("v10 test (7) failed"); + if (v10.get(4) != 55) throw new RuntimeException("v10 test (8) failed"); + + IntVector v11 = new IntVector(java.util.Arrays.asList(11, 22, 33, 44)); + v11.listIterator(0); + v11.listIterator(v11.size()); + try { + v11.listIterator(v11.size() + 1); + throw new RuntimeException("v11 test (1) failed"); + } catch (IndexOutOfBoundsException e) { + } + try { + v11.listIterator(-1); + throw new RuntimeException("v11 test (2) failed"); + } catch (IndexOutOfBoundsException e) { + } } } diff --git a/Lib/java/std_list.i b/Lib/java/std_list.i index e511ea006..af6ac075f 100644 --- a/Lib/java/std_list.i +++ b/Lib/java/std_list.i @@ -55,6 +55,8 @@ namespace std { private Iterator last; private java.util.ListIterator<$typemap(jboxtype, T)> init(int index) { + if (index < 0 || index > $javaclassname.this.size()) + throw new IndexOutOfBoundsException("Index: " + index); pos = $javaclassname.this.begin(); pos = pos.advance_unchecked(index); return this;