mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
fixes #2341 - inconsistent bounds checks
The core datastructure IntLost, FloatList, and StringList all have
unsafe .get methods that do not perform bounds checking. This is in
contrast to their .remove methods, which do perform bounds checking.
Prior to this patch, the following would print 0:
IntList il = new IntList();
println(il.get(5));
But if we tried to *remove* that element, we would get an
ArrayIndexOutOfBoundException:
il.remove(5);
This patch causes calls to .get to throw exceptions instead of returning
0 (or null in the case of StringList) for uninitialized values.
This commit is contained in:
@@ -110,6 +110,9 @@ public class FloatList implements Iterable<Float> {
|
||||
* @brief Get an entry at a particular index
|
||||
*/
|
||||
public float get(int index) {
|
||||
if (index >= count) {
|
||||
throw new ArrayIndexOutOfBoundsException(index);
|
||||
}
|
||||
return data[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -130,6 +130,9 @@ public class IntList implements Iterable<Integer> {
|
||||
* @brief Get an entry at a particular index
|
||||
*/
|
||||
public int get(int index) {
|
||||
if (index >= this.count) {
|
||||
throw new ArrayIndexOutOfBoundsException(index);
|
||||
}
|
||||
return data[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,9 @@ public class StringList implements Iterable<String> {
|
||||
* @brief Get an entry at a particular index
|
||||
*/
|
||||
public String get(int index) {
|
||||
if (index >= count) {
|
||||
throw new ArrayIndexOutOfBoundsException(index);
|
||||
}
|
||||
return data[index];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user