Skip to content

Consider Java implicit exceptions when building the CFG #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ public static void main(String args[]) {
try {
int[] a=new int[4];
a[4]=0;
throw new RuntimeException();
}
catch (ArrayIndexOutOfBoundsException exc) {
assert false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ArrayIndexOutOfBoundsExceptionTest.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 9 function.*: FAILURE$
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 8 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class ArrayIndexOutOfBoundsExceptionTest {
public static void main(String args[]) {
try {
int[] a=new int[4];
int i=a[5];
}
catch (ArrayIndexOutOfBoundsException exc) {
assert false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
ArrayIndexOutOfBoundsExceptionTest.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 8 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ public static void main(String args[]) {
try {
Object x = new Integer(0);
String y = (String)x;
throw new RuntimeException();
}
catch (ClassCastException exc) {
assert false;
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-java/ClassCastException1/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ClassCastExceptionTest.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file ClassCastExceptionTest.java line 9 function.*: FAILURE$
^.*assertion at file ClassCastExceptionTest.java line 8 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public static void main(String args[]) {
try {
A c = new C();
B b = (B)c;
// TODO: an explicit throw is currently needed in order
// for CBMC to convert the exception handler
throw new RuntimeException();
}
catch (ClassCastException exc) {
assert false;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class NegativeArraySizeExceptionTest {
public static void main(String args[]) {
try {
int a[]=new int[-1];
}
catch (NegativeArraySizeException exc) {
assert false;
}
}
}
9 changes: 9 additions & 0 deletions regression/cbmc-java/NegativeArraySizeException/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
NegativeArraySizeExceptionTest.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file NegativeArraySizeExceptionTest.java line 7 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file modified regression/cbmc-java/NullPointerException2/Test.class
Binary file not shown.
3 changes: 0 additions & 3 deletions regression/cbmc-java/NullPointerException2/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public static void main(String args[]) {
A a=null;
try {
a.i=0;
// TODO: an explicit throw is currently needed in order
// for CBMC to convert the exception handler
throw new B();
}
catch (NullPointerException exc) {
assert false;
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-java/NullPointerException2/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Test.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file Test.java line 17 function.*: FAILURE$
^.*assertion at file Test.java line 14 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file modified regression/cbmc-java/NullPointerException3/Test.class
Binary file not shown.
3 changes: 0 additions & 3 deletions regression/cbmc-java/NullPointerException3/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public static void main(String args[]) {
A a=null;
try {
int i=a.i;
// TODO: an explicit throw is currently needed in order
// for CBMC to convert the exception handler
throw new B();
}
catch (NullPointerException exc) {
assert false;
Expand Down
2 changes: 1 addition & 1 deletion regression/cbmc-java/NullPointerException3/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Test.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file Test.java line 17 function.*: FAILURE$
^.*assertion at file Test.java line 14 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
7 changes: 7 additions & 0 deletions src/java_bytecode/java_bytecode_convert_method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,13 @@ codet java_bytecode_convert_methodt::convert_instructions(
}

if(i_it->statement=="athrow" ||
i_it->statement=="putfield" ||
i_it->statement=="getfield" ||
i_it->statement=="checkcast" ||
i_it->statement=="newarray" ||
i_it->statement=="anewarray" ||
i_it->statement==patternt("?astore") ||
i_it->statement==patternt("?aload") ||
i_it->statement=="invokestatic" ||
i_it->statement=="invokevirtual" ||
i_it->statement=="invokespecial" ||
Expand Down