Skip to content

Commit cd2ef4b

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 653d887 commit cd2ef4b

6 files changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
assert3.class
3+
--throw-assertion-error --disable-uncaught-exception-check
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,7 @@ void java_bytecode_convert_methodt::convert_athrow(
22522252
exprt::operandst &results) const
22532253
{
22542254
if(
2255+
!throw_assertion_error &&
22552256
uncaught_exceptions_domaint::get_exception_type(op[0].type()) ==
22562257
"java::java.lang.AssertionError")
22572258
{
@@ -3087,6 +3088,7 @@ void java_bytecode_convert_method(
30873088
symbol_table_baset &symbol_table,
30883089
message_handlert &message_handler,
30893090
size_t max_array_length,
3091+
bool throw_assertion_error,
30903092
optionalt<ci_lazy_methods_neededt> needed_lazy_methods,
30913093
java_string_library_preprocesst &string_preprocess,
30923094
const class_hierarchyt &class_hierarchy)
@@ -3105,6 +3107,7 @@ void java_bytecode_convert_method(
31053107
symbol_table,
31063108
message_handler,
31073109
max_array_length,
3110+
throw_assertion_error,
31083111
needed_lazy_methods,
31093112
string_preprocess,
31103113
class_hierarchy);

jbmc/src/java_bytecode/java_bytecode_convert_method.h

+1
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

+3
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

+2
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"))
@@ -1030,6 +1031,7 @@ bool java_bytecode_languaget::convert_single_method(
10301031
symbol_table,
10311032
get_message_handler(),
10321033
max_user_array_length,
1034+
throw_assertion_error,
10331035
std::move(needed_lazy_methods),
10341036
string_preprocess,
10351037
class_hierarchy);

jbmc/src/java_bytecode/java_bytecode_language.h

+5
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)