Skip to content

Commit e6acbba

Browse files
committed
fixes processing#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.
1 parent c838dc1 commit e6acbba

3 files changed

Lines changed: 9 additions & 0 deletions

File tree

core/src/processing/data/FloatList.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public void clear() {
110110
* @brief Get an entry at a particular index
111111
*/
112112
public float get(int index) {
113+
if (index >= count) {
114+
throw new ArrayIndexOutOfBoundsException(index);
115+
}
113116
return data[index];
114117
}
115118

core/src/processing/data/IntList.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ public void clear() {
130130
* @brief Get an entry at a particular index
131131
*/
132132
public int get(int index) {
133+
if (index >= this.count) {
134+
throw new ArrayIndexOutOfBoundsException(index);
135+
}
133136
return data[index];
134137
}
135138

core/src/processing/data/StringList.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ public void clear() {
113113
* @brief Get an entry at a particular index
114114
*/
115115
public String get(int index) {
116+
if (index >= count) {
117+
throw new ArrayIndexOutOfBoundsException(index);
118+
}
116119
return data[index];
117120
}
118121

0 commit comments

Comments
 (0)