Skip to content

Commit 643e9f1

Browse files
committed
Java object factory: initialize AbstractStringBuilder-derived types correctly
These are currently initialized as if they are directly derived from Object, which causes a crash due to the type inconsistency between StringBuilder { AbstractStringBuilder { Object { } } } and StringBuilder { Object { } }
1 parent 9480092 commit 643e9f1

14 files changed

+49
-5
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public class Test {
2+
3+
public static void testme(StringBuilder builder, StringBuffer buffer) {
4+
5+
}
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package java.lang;
2+
3+
public class AbstractStringBuilder implements CharSequence {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package java.lang;
2+
3+
interface CharSequence {
4+
5+
}
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package java.lang;
2+
3+
public class String implements CharSequence {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package java.lang;
2+
3+
public class StringBuffer extends AbstractStringBuilder {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package java.lang;
2+
3+
public class StringBuilder extends AbstractStringBuilder {
4+
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CORE
2+
Test.class
3+
--function Test.testme
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
--
7+
type mismatch

jbmc/src/java_bytecode/java_object_factory.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -570,13 +570,18 @@ codet initialize_nondet_string_struct(
570570
? "java::java.lang.String"
571571
: "java::" + id2string(struct_type.get_tag());
572572

573-
const symbol_typet jlo_symbol("java::java.lang.Object");
574-
const struct_typet &jlo_type = to_struct_type(ns.follow(jlo_symbol));
575-
struct_exprt jlo_init(jlo_symbol);
576-
java_root_class_init(jlo_init, jlo_type, class_id);
573+
const struct_typet &superclass_type =
574+
to_struct_type(ns.follow(struct_type.components().at(0).type()));
575+
576+
null_message_handlert nullout;
577+
exprt superclass_init =
578+
zero_initializer(superclass_type, loc, ns, nullout);
579+
580+
set_class_identifier(
581+
to_struct_expr(superclass_init), ns, symbol_typet(class_id));
577582

578583
struct_exprt struct_expr(obj.type());
579-
struct_expr.copy_to_operands(jlo_init);
584+
struct_expr.copy_to_operands(superclass_init);
580585

581586
// In case the type for string was not added to the symbol table,
582587
// (typically when string refinement is not activated), `struct_type`

0 commit comments

Comments
 (0)