Skip to content

Commit bb6f859

Browse files
Enable throwing of AssertionError
Introduces --throw-assertion-error which allows to propgate AssertionError as performed in the JVM rather than using a goto ASSERT statement.
1 parent 9b84188 commit bb6f859

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

jbmc/regression/jbmc/assert3/test_propagate_no_uncaught.desc renamed to jbmc/regression/jbmc/assert3/test_throw_no_uncaught.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
CORE
22
assert3.class
3-
--propagate-assertion-error --disable-uncaught-exception-check
3+
--throw-assertion-error --disable-uncaught-exception-check
44
^EXIT=0$
55
^SIGNAL=0$
66
^VERIFICATION SUCCESSFUL$

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ codet java_bytecode_convert_methodt::convert_instructions(
12411241
{
12421242
PRECONDITION(op.size() == 1 && results.size() == 1);
12431243
if(
1244+
!throw_assertion_error &&
12441245
uncaught_exceptions_domaint::get_exception_type(op[0].type()) ==
12451246
"java::java.lang.AssertionError")
12461247
{
@@ -2867,6 +2868,7 @@ void java_bytecode_convert_method(
28672868
symbol_table_baset &symbol_table,
28682869
message_handlert &message_handler,
28692870
size_t max_array_length,
2871+
bool throw_assertion_error,
28702872
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
28712873
java_string_library_preprocesst &string_preprocess,
28722874
const class_hierarchyt &class_hierarchy)
@@ -2885,6 +2887,7 @@ void java_bytecode_convert_method(
28852887
symbol_table,
28862888
message_handler,
28872889
max_array_length,
2890+
throw_assertion_error,
28882891
needed_lazy_methods,
28892892
string_preprocess,
28902893
class_hierarchy);

jbmc/src/java_bytecode/java_bytecode_convert_method.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ void java_bytecode_convert_method(
3333
symbol_table_baset &symbol_table,
3434
message_handlert &message_handler,
3535
size_t max_array_length,
36+
bool throw_assertion_error,
3637
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
3738
java_string_library_preprocesst &string_preprocess,
3839
const class_hierarchyt &class_hierarchy);

jbmc/src/java_bytecode/java_bytecode_convert_method_class.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class java_bytecode_convert_methodt:public messaget
3636
symbol_table_baset &symbol_table,
3737
message_handlert &_message_handler,
3838
size_t _max_array_length,
39+
bool throw_assertion_error,
3940
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
4041
java_string_library_preprocesst &_string_preprocess,
4142
const class_hierarchyt &class_hierarchy)
4243
: messaget(_message_handler),
4344
symbol_table(symbol_table),
4445
max_array_length(_max_array_length),
46+
throw_assertion_error(throw_assertion_error),
4547
needed_lazy_methods(std::move(needed_lazy_methods)),
4648
string_preprocess(_string_preprocess),
4749
slots_for_parameters(0),
@@ -64,6 +66,7 @@ class java_bytecode_convert_methodt:public messaget
6466
protected:
6567
symbol_table_baset &symbol_table;
6668
const size_t max_array_length;
69+
const bool throw_assertion_error;
6770
optionalt<ci_lazy_methods_neededt> needed_lazy_methods;
6871

6972
/// Fully qualified name of the method under translation.

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void java_bytecode_languaget::get_language_options(const cmdlinet &cmd)
4747
string_refinement_enabled=cmd.isset("refine-strings");
4848
throw_runtime_exceptions=cmd.isset("java-throw-runtime-exceptions");
4949
assert_uncaught_exceptions = !cmd.isset("disable-uncaught-exception-check");
50+
throw_assertion_error = cmd.isset("throw-assertion-error");
5051
threading_support = cmd.isset("java-threading");
5152

5253
if(cmd.isset("java-max-input-array-length"))
@@ -1038,6 +1039,7 @@ bool java_bytecode_languaget::convert_single_method(
10381039
symbol_table,
10391040
get_message_handler(),
10401041
max_user_array_length,
1042+
throw_assertion_error,
10411043
std::move(needed_lazy_methods),
10421044
string_preprocess,
10431045
class_hierarchy);

jbmc/src/java_bytecode/java_bytecode_language.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Author: Daniel Kroening, [email protected]
2929
// clang-format off
3030
#define JAVA_BYTECODE_LANGUAGE_OPTIONS /*NOLINT*/ \
3131
"(disable-uncaught-exception-check)" \
32+
"(throw-assertion-error)" \
3233
"(java-assume-inputs-non-null)" \
3334
"(java-throw-runtime-exceptions)" \
3435
"(java-max-input-array-length):" \
@@ -43,6 +44,9 @@ Author: Daniel Kroening, [email protected]
4344
#define JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP /*NOLINT*/ \
4445
" --disable-uncaught-exception-check" \
4546
" ignore uncaught exceptions and errors\n" \
47+
" --throw-assertion-error throw java.lang.AssertionError on violated\n" /* NOLINT(*) */ \
48+
" assert statements instead of failing\n" \
49+
" at the location of the assert statement\n" /* NOLINT(*) */ \
4650
" --java-assume-inputs-non-null never initialize reference-typed parameter to the\n" /* NOLINT(*) */ \
4751
" entry point with null\n" /* NOLINT(*) */ \
4852
" --java-throw-runtime-exceptions make implicit runtime exceptions explicit\n" /* NOLINT(*) */ \
@@ -173,6 +177,7 @@ class java_bytecode_languaget:public languaget
173177
bool string_refinement_enabled;
174178
bool throw_runtime_exceptions;
175179
bool assert_uncaught_exceptions;
180+
bool throw_assertion_error;
176181
java_string_library_preprocesst string_preprocess;
177182
std::string java_cp_include_files;
178183

0 commit comments

Comments
 (0)