Skip to content

Feature/new instrumentation runtime exceptions #912

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

Closed
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
@@ -0,0 +1,14 @@
public class ArrayIndexOutOfBoundsExceptionTest {
public static void main(String args[]) {
try {
int[] a=new int[4];
a[6]=0;
// TODO: fix the bytecode convertion such that there is no need for
// an explicit throw in order to convert the handler
throw new RuntimeException();
}
catch(ArrayIndexOutOfBoundsException exc) {
assert false;
}
}
}
9 changes: 9 additions & 0 deletions regression/cbmc-java/ArrayIndexOutOfBoundsException/test.desc
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 11 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file added regression/cbmc-java/ClassCastException1/A.class
Binary file not shown.
Binary file added regression/cbmc-java/ClassCastException1/B.class
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class A {
int i;
}

class B {
int j;
}

public class ClassCastExceptionTest {
public static void main(String args[]) {
try {
Object x = new Integer(0);
String y=(String)x;
throw new RuntimeException();
}
catch (ClassCastException exc) {
assert false;
}

}
}
9 changes: 9 additions & 0 deletions regression/cbmc-java/ClassCastException1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
ClassCastExceptionTest.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file ClassCastExceptionTest.java line 17 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file added regression/cbmc-java/ClassCastException2/A.class
Binary file not shown.
Binary file added regression/cbmc-java/ClassCastException2/B.class
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class A {
int i;
}

class B {
int j;
}

public class ClassCastExceptionTest {
public static void main(String args[]) {
try {
Object x = new Integer(0);
String y=(String)x;
throw new RuntimeException();
}
catch (ClassCastException exc) {
assert false;
}

}
}
9 changes: 9 additions & 0 deletions regression/cbmc-java/ClassCastException2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
ClassCastExceptionTest.class

^EXIT=10$
^SIGNAL=0$
^.*Dynamic cast check: 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 NegativeArraySizeExceptionTest {
public static void main(String args[]) {
try {
int a[]=new int[-1];
throw new RuntimeException();
}
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 8 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file added regression/cbmc-java/NullPointerException2/A.class
Binary file not shown.
Binary file added regression/cbmc-java/NullPointerException2/B.class
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions regression/cbmc-java/NullPointerException2/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class B extends RuntimeException {}

class A {
int i;
}

public class Test {
public static void main(String args[]) {
A a=null;
try {
int i=a.i;
throw new B();
}
catch (NullPointerException exc) {
assert false;
}
}
}
9 changes: 9 additions & 0 deletions regression/cbmc-java/NullPointerException2/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class
--java-throw-runtime-exceptions
^EXIT=10$
^SIGNAL=0$
^.*assertion at file Test.java line 15 function.*: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
Binary file added regression/cbmc-java/NullPointerException3/A.class
Binary file not shown.
Binary file added regression/cbmc-java/NullPointerException3/B.class
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions regression/cbmc-java/NullPointerException3/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class B extends RuntimeException {}

class A {
int i;
}

public class Test {
public static void main(String args[]) {
A a=null;
try {
int i=a.i;
throw new B();
}
catch (NullPointerException exc) {
assert false;
}
}
}
9 changes: 9 additions & 0 deletions regression/cbmc-java/NullPointerException3/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class

^EXIT=10$
^SIGNAL=0$
^.*reference is null in \*a: FAILURE$
^VERIFICATION FAILED$
--
^warning: ignoring
1 change: 1 addition & 0 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,7 @@ void cbmc_parse_optionst::help()
// NOLINTNEXTLINE(whitespace/line_length)
" --java-max-vla-length limit the length of user-code-created arrays\n"
// NOLINTNEXTLINE(whitespace/line_length)
" --java-throw-runtime-exceptions Throw runtime exceptions when necessary"
" --java-cp-include-files regexp or JSON list of files to load (with '@' prefix)\n"
" --java-unwind-enum-static try to unwind loops in static initialization of enums\n"
"\n"
Expand Down
1 change: 1 addition & 0 deletions src/cbmc/cbmc_parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class optionst;
"(round-to-nearest)(round-to-plus-inf)(round-to-minus-inf)(round-to-zero)" \
"(graphml-witness):" \
"(java-max-vla-length):(java-unwind-enum-static)" \
"(java-throw-runtime-exceptions)" \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing help documentation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

"(java-cp-include-files):" \
"(localize-faults)(localize-faults-method):" \
"(lazy-methods)" \
Expand Down
Loading