Skip to content

Commit 0dd029d

Browse files
Prevent use of CharSequence as a class_identifier
CharSequence is abstract and should not appear as a class identifer. Instead we use Sring which implements CharSequence.
1 parent f4c9719 commit 0dd029d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/java_bytecode/java_object_factory.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,19 @@ codet initialize_nondet_string_struct(
571571

572572
// `obj` is `*expr`
573573
const struct_typet &struct_type = to_struct_type(ns.follow(obj.type()));
574-
const irep_idt &class_id = "java::" + id2string(struct_type.get_tag());
575-
576-
// @clsid = String and @lock = false:
574+
// @clsid = java::java.lang.String or similar.
575+
// We allow type StringBuffer and StringBuilder to be initialized
576+
// in the same way has String, because they have the same structure and
577+
// are treated in the same way by CBMC.
578+
// Note that CharSequence cannot be used as classid because it's abstract,
579+
// so it is replaced by String.
580+
// \todo allow StringBuffer and StringBuilder as classid for Charsequence
581+
const irep_idt &class_id =
582+
struct_type.get_tag() == "java.lang.CharSequence"
583+
? "java::java.lang.String"
584+
: "java::" + id2string(struct_type.get_tag());
585+
586+
// @lock = false:
577587
const symbol_typet jlo_symbol("java::java.lang.Object");
578588
const struct_typet &jlo_type = to_struct_type(ns.follow(jlo_symbol));
579589
struct_exprt jlo_init(jlo_symbol);

0 commit comments

Comments
 (0)