Skip to content

Commit 092f8e2

Browse files
committed
Lazy methods: fault in static initializer if a static method is called
Static method calls already cause clinit calls, but didn't previously cause the clinit method to be loaded.
1 parent 2d97393 commit 092f8e2

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed
322 Bytes
Binary file not shown.
530 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CORE
2+
test.class
3+
--lazy-methods --function test.main
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
VERIFICATION SUCCESSFUL
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
public class test {
3+
4+
public static void main() {
5+
6+
assert(other.getx()==1);
7+
8+
}
9+
10+
}
11+
12+
class other {
13+
14+
public static int x;
15+
public static int getx() { return x; }
16+
17+
static {
18+
x=1;
19+
}
20+
21+
}

src/java_bytecode/java_bytecode_convert_method.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,11 @@ codet java_bytecode_convert_methodt::convert_instructions(
14181418
// static binding
14191419
call.function()=symbol_exprt(arg0.get(ID_identifier), arg0.type());
14201420
if(lazy_methods)
1421+
{
14211422
lazy_methods->add_needed_method(arg0.get(ID_identifier));
1423+
// Calling a static method causes static initialization:
1424+
lazy_methods->add_needed_class(arg0.get(ID_C_class));
1425+
}
14221426
}
14231427

14241428
call.function().add_source_location()=loc;

0 commit comments

Comments
 (0)