Skip to content

Object factory: permit null pointers within java.lang.Class #2202

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

Merged
Merged
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 added jbmc/regression/jbmc/class-fields/Test.class
Binary file not shown.
10 changes: 10 additions & 0 deletions jbmc/regression/jbmc/class-fields/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Test {

public static void main() {

java.lang.Class c = Test.class;
assert false;

}

}
Binary file not shown.
11 changes: 11 additions & 0 deletions jbmc/regression/jbmc/class-fields/java/lang/Class.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package java.lang;

public class Class {

public Integer field;

protected void cproverNondetInitialize() {
org.cprover.CProver.assume(field == null);
}

}
9 changes: 9 additions & 0 deletions jbmc/regression/jbmc/class-fields/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CORE
Test.class

^EXIT=10$
^SIGNAL=0$
^VERIFICATION FAILED$
assertion at file Test\.java line 6.*: FAILURE$
--
^warning: ignoring
5 changes: 0 additions & 5 deletions jbmc/src/java_bytecode/java_entry_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,6 @@ static void java_static_lifetime_init(
if(allow_null)
{
irep_idt nameid=sym.symbol_expr().get_identifier();
std::string namestr=id2string(nameid);
const std::string suffix="@class_model";
// Static '.class' fields are always non-null.
if(has_suffix(namestr, suffix))
allow_null=false;
if(allow_null && is_java_string_literal_id(nameid))
allow_null=false;
if(allow_null && is_non_null_library_global(nameid))
Expand Down
6 changes: 1 addition & 5 deletions jbmc/src/java_bytecode/java_object_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,6 @@ void java_object_factoryt::gen_nondet_pointer_init(

auto set_null_inst=get_null_assignment(expr, pointer_type);

// Determine whether the pointer can be null. In particular the pointers
// inside the java.lang.Class class shall not be null
const bool not_null = !allow_null || class_identifier == "java.lang.Class";

// Alternatively, if this is a void* we *must* initialise with null:
// (This can currently happen for some cases of #exception_value)
bool must_be_null=
Expand All @@ -889,7 +885,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
// <expr> = nullptr;
new_object_assignments.add(set_null_inst);
}
else if(not_null)
else if(!allow_null)
{
// Add the following code to assignments:
// <expr> = <aoe>;
Expand Down