Skip to content

Commit 856bd3b

Browse files
committed
Assert there are no null's in arguments or in Object[] arrays
1 parent 2bb5176 commit 856bd3b

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/main/java/org/truffleruby/core/array/ArrayHelpers.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,13 @@ public static void setSize(RubyArray array, int size) {
2929
array.size = size;
3030
}
3131

32+
private static boolean assertNoNullElement(Object store, int size) {
33+
return !(store instanceof Object[]) || ArrayUtils.assertNoNullElement((Object[]) store, size);
34+
}
35+
3236
public static RubyArray createArray(RubyContext context, RubyLanguage language, Object store, int size) {
3337
assert !(store instanceof Object[]) || store.getClass() == Object[].class;
38+
assert assertNoNullElement(store, size);
3439
return new RubyArray(context.getCoreLibrary().arrayClass, language.arrayShape, store, size);
3540
}
3641

src/main/java/org/truffleruby/core/array/ArrayUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ public abstract class ArrayUtils {
2020

2121
public static final Object[] EMPTY_ARRAY = new Object[0];
2222

23+
public static boolean assertNoNullElement(Object[] array, int size) {
24+
assert size <= array.length;
25+
for (int i = 0; i < size; i++) {
26+
final Object element = array[i];
27+
assert element != null : element;
28+
}
29+
return true;
30+
}
31+
32+
public static boolean assertNoNullElement(Object[] array) {
33+
return assertNoNullElement(array, array.length);
34+
}
35+
2336
/** Extracts part of an array into a newly allocated byte[] array. Does not perform safety checks on parameters.
2437
*
2538
* @param source the source array whose values should be extracted

src/main/java/org/truffleruby/language/arguments/RubyArguments.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public static Object[] pack(
7070
assert declarationContext != null;
7171
assert self != null;
7272
assert arguments != null;
73+
assert ArrayUtils.assertNoNullElement(arguments);
74+
7375
assert callerFrameOrVariables == null ||
7476
callerFrameOrVariables instanceof MaterializedFrame ||
7577
callerFrameOrVariables instanceof SpecialVariableStorage ||

0 commit comments

Comments
 (0)