Skip to content

Commit 639ad43

Browse files
Add static-values tests with class substitution
This adds a test in which an non-empty class is replaced by an empty class after compilation and before JBMC is called. This used to cause a crash in the retrieval of static values. This kind of substitution is not uncommon in the jar packaging of libraries. A similar error was triggered when analyising a project which used mongodb as a dependency, and mongodb seems to use such tricks.
1 parent 7133018 commit 639ad43

File tree

6 files changed

+25
-0
lines changed

6 files changed

+25
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public class ClassWithNoStaticField {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public class ClassWithStaticFieldToBeSubstituted { public static int i = 23; }
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public class EmptyNonEmpty {
2+
3+
/// This test is meant to illustrate what happens when a class
4+
/// with a static field is substituted with an empty one after compilation.
5+
public int test() {
6+
int x = ClassWithStaticFieldToBeSubstituted.i;
7+
return x;
8+
}
9+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CORE
2+
EmptyNonEmpty.class
3+
--unwind 1 --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --static-values clinit-state.json --function EmptyNonEmpty.test
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
--
9+
This tests what happens when the class with a static field is substituted with
10+
a class with no static field after compilation: after compiling
11+
ClassWithStaticFieldToBeSubstitued.class and ClassWithNoStaticField.class,
12+
we copy ClassWithNoStaticField.class to ClassWithStaticFieldToBeSubstitued.class
13+
in order to overwrite it.
14+
We should at least ensure that JBMC does not crash.

0 commit comments

Comments
 (0)