Skip to content

Commit 7a85377

Browse files
committed
Fix primitive wrapper types in JSON value retriever
Following the format of the json-io library, the JSON input to the value retriever does not distinguish between primitive types and their corresponding wrapper types. A class Foo with a field fooField of type Integer might appear as { "@type":"org.cprover.Foo", "fooField":100 } To support this "primitive representation", we need a special case in the struct assignment part.
1 parent 639b864 commit 7a85377

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

jbmc/src/java_bytecode/assignments_from_json.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,16 @@ static void assign_struct_components_from_json(
532532
assign_struct_components_from_json(member_expr, json, info);
533533
else // component is class field (pointer to struct)
534534
{
535-
const jsont member_json = json[id2string(component_name)];
535+
const auto member_json = [&]() -> jsont {
536+
if(
537+
is_primitive_wrapper_type_name(id2string(
538+
strip_java_namespace_prefix(java_class_type.get_name()))) &&
539+
id2string(component_name) == "value")
540+
{
541+
return get_untyped_primitive(json);
542+
}
543+
return json[id2string(component_name)];
544+
}();
536545
assign_from_json_rec(member_expr, member_json, {}, info);
537546
}
538547
}

jbmc/src/java_bytecode/java_utils.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,20 @@ bool is_java_string_type(const struct_typet &struct_type)
3838
struct_type.has_component("data");
3939
}
4040

41+
bool is_primitive_wrapper_type_name(const std::string &type_name)
42+
{
43+
static const std::unordered_set<std::string> primitive_wrapper_type_names = {
44+
"java.lang.Boolean",
45+
"java.lang.Byte",
46+
"java.lang.Character",
47+
"java.lang.Double",
48+
"java.lang.Float",
49+
"java.lang.Integer",
50+
"java.lang.Long",
51+
"java.lang.Short"};
52+
return primitive_wrapper_type_names.count(type_name) > 0;
53+
}
54+
4155
unsigned java_local_variable_slots(const typet &t)
4256
{
4357

jbmc/src/java_bytecode/java_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ bool java_is_array_type(const typet &type);
3131
/// and in particular may not have length and data fields.
3232
bool is_java_string_type(const struct_typet &struct_type);
3333

34+
/// Returns true iff the argument is the fully qualified name of a Java
35+
/// primitive wrapper type.
36+
bool is_primitive_wrapper_type_name(const std::string &type_name);
37+
3438
void generate_class_stub(
3539
const irep_idt &class_name,
3640
symbol_table_baset &symbol_table,

0 commit comments

Comments
 (0)