Skip to content

Commit 074a57e

Browse files
committed
Always check for null on a member access
1 parent 6609f45 commit 074a57e

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/java_bytecode/java_bytecode_instrument.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class java_bytecode_instrumentt:public messaget
6666

6767
codet check_null_dereference(
6868
const exprt &expr,
69-
const source_locationt &original_loc,
70-
const bool assertion_enabled);
69+
const source_locationt &original_loc);
7170

7271
codet check_class_cast(
7372
const exprt &class1,
@@ -271,8 +270,7 @@ codet java_bytecode_instrumentt::check_class_cast(
271270
/// assertion checking the subtype relation
272271
codet java_bytecode_instrumentt::check_null_dereference(
273272
const exprt &expr,
274-
const source_locationt &original_loc,
275-
const bool assertion_enabled)
273+
const source_locationt &original_loc)
276274
{
277275
const equal_exprt equal_expr(
278276
expr,
@@ -283,17 +281,12 @@ codet java_bytecode_instrumentt::check_null_dereference(
283281
equal_expr,
284282
original_loc, "java.lang.NullPointerException");
285283

286-
if(assertion_enabled)
287-
{
288-
code_assertt check((not_exprt(equal_expr)));
289-
check.add_source_location()
290-
.set_comment("Throw null");
291-
check.add_source_location()
292-
.set_property_class("null-pointer-exception");
293-
return check;
294-
}
295-
296-
return code_skipt();
284+
code_assertt check((not_exprt(equal_expr)));
285+
check.add_source_location()
286+
.set_comment("Throw null");
287+
check.add_source_location()
288+
.set_property_class("null-pointer-exception");
289+
return check;
297290
}
298291

299292
/// Checks whether `length`>=0 and throws NegativeArraySizeException/
@@ -462,8 +455,7 @@ void java_bytecode_instrumentt::instrument_code(exprt &expr)
462455
block.copy_to_operands(
463456
check_null_dereference(
464457
code_function_call.arguments()[0],
465-
code_function_call.source_location(),
466-
true));
458+
code_function_call.source_location()));
467459
}
468460

469461
for(const auto &arg : code_function_call.arguments())
@@ -528,8 +520,7 @@ codet java_bytecode_instrumentt::instrument_expr(
528520
result.copy_to_operands(
529521
check_null_dereference(
530522
expr.op0(),
531-
expr.source_location(),
532-
true));
523+
expr.source_location()));
533524
}
534525
else if(statement==ID_java_new_array)
535526
{
@@ -558,8 +549,7 @@ codet java_bytecode_instrumentt::instrument_expr(
558549
codet null_dereference_check=
559550
check_null_dereference(
560551
dereference_expr.op0(),
561-
dereference_expr.source_location(),
562-
false);
552+
dereference_expr.source_location());
563553
result.move_to_operands(null_dereference_check);
564554
}
565555

0 commit comments

Comments
 (0)