@@ -496,6 +496,22 @@ static void assign_array_from_json(
496
496
assign_array_data_component_from_json (expr, json, type_from_array, info);
497
497
}
498
498
499
+ // / Allocate an array of size given by the json object, and assign its elemnts
500
+ // / according tho the json content.
501
+ static void allocate_and_assign_array_from_json (
502
+ const exprt &array,
503
+ const jsont &json,
504
+ const optionalt<std::string> &type_from_array,
505
+ object_creation_infot &info)
506
+ {
507
+ PRECONDITION (is_java_array_type (array.type ()));
508
+ const auto &element_type =
509
+ java_array_element_type (to_struct_tag_type (array.type ().subtype ()));
510
+ const json_arrayt json_array = get_untyped_array (json, element_type);
511
+ allocate_array (array, from_integer (json_array.size (), java_int_type ()), info);
512
+ assign_array_data_component_from_json (array, json, type_from_array, info);
513
+ }
514
+
499
515
// / One of the cases in the recursive algorithm: the case where \p expr
500
516
// / represents a string.
501
517
// / See \ref assign_from_json_rec.
@@ -769,10 +785,19 @@ static void assign_reference_from_json(
769
785
{
770
786
if (is_java_array_type (expr.type ()))
771
787
{
772
- INVARIANT (
773
- reference.array_length , " an array reference should stores its length" );
774
- assign_array_from_json (
775
- reference.expr , json, *reference.array_length , type_from_array, info);
788
+ if (has_nondet_length (json))
789
+ {
790
+ const exprt length =
791
+ nondet_length (info.allocate_objects , info.block , info.loc );
792
+ allocate_array (expr, length, info);
793
+ INVARIANT (
794
+ reference.array_length ,
795
+ " an array reference should stores its length" );
796
+ assign_array_from_json (
797
+ reference.expr , json, *reference.array_length , type_from_array, info);
798
+ }
799
+ else
800
+ allocate_and_assign_array_from_json (expr, json, type_from_array, info);
776
801
}
777
802
else
778
803
assign_struct_from_json (dereference_exprt (reference.expr ), json, info);
@@ -811,10 +836,15 @@ void assign_from_json_rec(
811
836
}
812
837
else if (is_java_array_type (expr.type ()))
813
838
{
814
- const exprt length =
815
- nondet_length (info.allocate_objects , info.block , info.loc );
816
- allocate_array (expr, length, info);
817
- assign_array_from_json (expr, json, length, type_from_array, info);
839
+ if (has_nondet_length (json))
840
+ {
841
+ const exprt length =
842
+ nondet_length (info.allocate_objects , info.block , info.loc );
843
+ allocate_array (expr, length, info);
844
+ assign_array_from_json (expr, json, length, type_from_array, info);
845
+ }
846
+ else
847
+ allocate_and_assign_array_from_json (expr, json, type_from_array, info);
818
848
}
819
849
else if (
820
850
const auto runtime_type =
0 commit comments