Skip to content

Commit 1667307

Browse files
authored
Merge pull request #1469 from antlechner/antonia/fix/ci_lazy_method_exception_types
Lazy methods: mark JVM-generated exceptions as always available (fixes TG-774)
2 parents c99c2e4 + 94a6ad4 commit 1667307

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+179
-3
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class ArithmeticExceptionTest {
2+
public static void main(String args[]) {
3+
try {
4+
int i=0;
5+
int j=10/i;
6+
}
7+
catch(Exception exc) {
8+
assert false;
9+
}
10+
}
11+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class ArithmeticException extends RuntimeException {
4+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class RuntimeException extends Exception {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArithmeticExceptionTest.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^.*assertion at file ArithmeticExceptionTest.java line 8 function.*: FAILURE$
7+
^VERIFICATION FAILED
8+
--
9+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class ArrayIndexOutOfBoundsExceptionTest {
2+
public static void main(String args[]) {
3+
try {
4+
int[] a=new int[4];
5+
a[4]=0;
6+
}
7+
catch (Exception exc) {
8+
assert false;
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class IndexOutOfBoundsException extends RuntimeException {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class RuntimeException extends Exception {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ArrayIndexOutOfBoundsExceptionTest.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^.*assertion at file ArrayIndexOutOfBoundsExceptionTest.java line 8 function.*: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring
197 Bytes
Binary file not shown.
197 Bytes
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class A {}
2+
3+
class B {}
4+
5+
public class ClassCastExceptionTest {
6+
public static void main(String args[]) {
7+
try {
8+
Object a = new A();
9+
B b = (B)a;
10+
}
11+
catch (Exception exc) {
12+
assert false;
13+
}
14+
}
15+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class ClassCastException extends RuntimeException {
4+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class RuntimeException extends Exception {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
ClassCastExceptionTest.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^.*assertion at file ClassCastExceptionTest.java line 12 function.*: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class NegativeArraySizeExceptionTest {
2+
public static void main(String args[]) {
3+
try {
4+
int a[]=new int[-1];
5+
}
6+
catch (Exception exc) {
7+
assert false;
8+
}
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class NegativeArraySizeException extends RuntimeException {
4+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class RuntimeException extends Exception {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
NegativeArraySizeExceptionTest.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^.*assertion at file NegativeArraySizeExceptionTest.java line 7 function.*: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring
195 Bytes
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class A {
2+
int i;
3+
}
4+
5+
public class Test {
6+
public static void main(String args[]) {
7+
A a=null;
8+
try {
9+
a.i=0;
10+
}
11+
catch (Exception exc) {
12+
assert false;
13+
}
14+
}
15+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class NullPointerException extends RuntimeException {
4+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package java.lang;
2+
3+
public class RuntimeException extends Exception {
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
Test.class
3+
--java-throw-runtime-exceptions
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^.*assertion at file Test.java line 12 function.*: FAILURE$
7+
^VERIFICATION FAILED$
8+
--
9+
^warning: ignoring

src/java_bytecode/java_bytecode_instrument.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Date: June 2017
88
99
\*******************************************************************/
1010

11+
#include "java_bytecode_instrument.h"
12+
1113
#include <util/arith_tools.h>
1214
#include <util/fresh_symbol.h>
1315
#include <util/std_code.h>
@@ -18,7 +20,6 @@ Date: June 2017
1820
#include <goto-programs/goto_functions.h>
1921

2022
#include "java_bytecode_convert_class.h"
21-
#include "java_bytecode_instrument.h"
2223
#include "java_entry_point.h"
2324
#include "java_root_class.h"
2425
#include "java_types.h"
@@ -79,6 +80,15 @@ class java_bytecode_instrumentt:public messaget
7980
};
8081

8182

83+
const std::vector<irep_idt> exception_needed_classes =
84+
{
85+
"java.lang.ArithmeticException",
86+
"java.lang.ArrayIndexOutOfBoundsException",
87+
"java.lang.ClassCastException",
88+
"java.lang.NegativeArraySizeException",
89+
"java.lang.NullPointerException"
90+
};
91+
8292
/// Creates a class stub for exc_name and generates a
8393
/// conditional GOTO such that exc_name is thrown when
8494
/// cond is met.

src/java_bytecode/java_bytecode_instrument.h

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Date: June 2017
1111
#ifndef CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_INSTRUMENT_H
1212
#define CPROVER_JAVA_BYTECODE_JAVA_BYTECODE_INSTRUMENT_H
1313

14+
#include <util/symbol_table.h>
15+
#include <util/message.h>
16+
#include <util/irep.h>
17+
1418
void java_bytecode_instrument_symbol(
1519
symbol_table_baset &symbol_table,
1620
symbolt &symbol,
@@ -22,4 +26,6 @@ void java_bytecode_instrument(
2226
const bool throw_runtime_exceptions,
2327
message_handlert &_message_handler);
2428

29+
extern const std::vector<irep_idt> exception_needed_classes;
30+
2531
#endif

src/java_bytecode/java_bytecode_language.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,19 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
6161
else
6262
lazy_methods_mode=LAZY_METHODS_MODE_EAGER;
6363

64+
if(cmd.isset("java-throw-runtime-exceptions"))
65+
{
66+
throw_runtime_exceptions = true;
67+
java_load_classes.insert(
68+
java_load_classes.end(),
69+
exception_needed_classes.begin(),
70+
exception_needed_classes.end());
71+
}
6472
if(cmd.isset("java-load-class"))
6573
{
66-
for(const auto &c : cmd.get_values("java-load-class"))
67-
java_load_classes.push_back(c);
74+
const auto &values = cmd.get_values("java-load-class");
75+
java_load_classes.insert(
76+
java_load_classes.end(), values.begin(), values.end());
6877
}
6978

7079
const std::list<std::string> &extra_entry_points=

0 commit comments

Comments
 (0)