Skip to content

Commit c659d13

Browse files
authored
Merge pull request #1197 from smowton/smowton/feature/virtual_call_null_check
Add more NullPointerException throw sites
2 parents 96826e7 + 074a57e commit c659d13

File tree

16 files changed

+116
-51
lines changed

16 files changed

+116
-51
lines changed
Binary file not shown.

regression/cbmc-java/NondetArray2/NondetArray2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ void main()
88

99
int num = 0;
1010
for (Integer i : ints) {
11+
if(i == null)
12+
continue;
1113
num *= i.intValue();
1214
}
1315
assert num == 0;
Binary file not shown.

regression/cbmc-java/NondetArray3/NondetArray3.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ void main()
99

1010
int num = 0;
1111
for (Integer i : ints) {
12+
if(i == null)
13+
continue;
1214
num *= i.intValue();
1315
}
1416
assert num == 0;
566 Bytes
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
VERIFICATION FAILED
7+
assertion at file test\.java line 9 function java::test\.main:\(\)V bytecode-index 12: FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
This test checks that accessing an array member, cf. a getfield or setfield bytecode,
12+
can produce a NullPointerException.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
public class test {
3+
public static void main () {
4+
try {
5+
int[] array = null;
6+
int x = array[0];
7+
}
8+
catch(NullPointerException e) {
9+
assert false;
10+
}
11+
}
12+
}
222 Bytes
Binary file not shown.
587 Bytes
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
test.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
VERIFICATION FAILED
7+
assertion at file test\.java line 9 function java::test\.main:\(\)V bytecode-index 10: FAILURE
8+
--
9+
^warning: ignoring
10+
--
11+
This test ensures that attempting a virtual call against a null pointer can produce a NullPointerException,
12+
even when there are no field accesses inside the method or inspection of its class identifier to trigger one.

0 commit comments

Comments
 (0)