Skip to content

Commit af02973

Browse files
authored
Merge pull request diffblue#2202 from smowton/smowton/fix/java-lang-class-fields
Object factory: permit null pointers within java.lang.Class
2 parents 8412eb0 + 8a59f6f commit af02973

File tree

7 files changed

+31
-10
lines changed

7 files changed

+31
-10
lines changed
598 Bytes
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class Test {
2+
3+
public static void main() {
4+
5+
java.lang.Class c = Test.class;
6+
assert false;
7+
8+
}
9+
10+
}
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package java.lang;
2+
3+
public class Class {
4+
5+
public Integer field;
6+
7+
protected void cproverNondetInitialize() {
8+
org.cprover.CProver.assume(field == null);
9+
}
10+
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CORE
2+
Test.class
3+
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^VERIFICATION FAILED$
7+
assertion at file Test\.java line 6.*: FAILURE$
8+
--
9+
^warning: ignoring

jbmc/src/java_bytecode/java_entry_point.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,6 @@ static void java_static_lifetime_init(
9494
if(allow_null)
9595
{
9696
irep_idt nameid=sym.symbol_expr().get_identifier();
97-
std::string namestr=id2string(nameid);
98-
const std::string suffix="@class_model";
99-
// Static '.class' fields are always non-null.
100-
if(has_suffix(namestr, suffix))
101-
allow_null=false;
10297
if(allow_null && is_java_string_literal_id(nameid))
10398
allow_null=false;
10499
if(allow_null && is_non_null_library_global(nameid))

jbmc/src/java_bytecode/java_object_factory.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,10 +874,6 @@ void java_object_factoryt::gen_nondet_pointer_init(
874874

875875
auto set_null_inst=get_null_assignment(expr, pointer_type);
876876

877-
// Determine whether the pointer can be null. In particular the pointers
878-
// inside the java.lang.Class class shall not be null
879-
const bool not_null = !allow_null || class_identifier == "java.lang.Class";
880-
881877
// Alternatively, if this is a void* we *must* initialise with null:
882878
// (This can currently happen for some cases of #exception_value)
883879
bool must_be_null=
@@ -889,7 +885,7 @@ void java_object_factoryt::gen_nondet_pointer_init(
889885
// <expr> = nullptr;
890886
new_object_assignments.add(set_null_inst);
891887
}
892-
else if(not_null)
888+
else if(!allow_null)
893889
{
894890
// Add the following code to assignments:
895891
// <expr> = <aoe>;

0 commit comments

Comments
 (0)