Skip to content

Commit a2d9412

Browse files
Add ability to overlay classes with new definitions of existing methods
Allows multiple definitions of the same class to appear on the classpath, so long as all but the first definition are marked with the attribute @java::com.diffblue.security.OverlayClassImplementation. Overlay class definitions can contain methods with the same signature as methods in the original class, so long as these are marked with the attribute @java::com.diffblue.security.OverlayMethodImplementation; such overlay methods are replaced in the original file with the version found in the last overlay on the classpath. Later definitions can also contain new supporting methods and fields that are merged in. This will allow insertion of Java methods into library classes to handle, for example, modelling dependency injection.
1 parent 26f4286 commit a2d9412

9 files changed

+654
-299
lines changed

regression/cbmc-java/generics_type_param/test.desc

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ GenericFields$SimpleGenericField.class
33
--cover location --function GenericFields\$SimpleGenericField.foo --verbosity 10
44
^EXIT=0$
55
^SIGNAL=0$
6-
Reading class AWrapper
7-
Reading class FWrapper
8-
Reading class IWrapper
6+
Parsing class AWrapper
7+
Parsing class FWrapper
8+
Parsing class IWrapper
99
--
1010
failed to load class \`AWrapper\'
1111
failed to load class \`FWrapper\'

src/java_bytecode/ci_lazy_methods.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,15 @@ bool ci_lazy_methodst::operator()(
8585
reachable_classes.push_back(main_class);
8686
else
8787
reachable_classes = main_jar_classes;
88-
for(const auto &classname : reachable_classes)
88+
for(const irep_idt &class_name : reachable_classes)
8989
{
90-
const auto &methods=
91-
java_class_loader.class_map.at(classname).parsed_class.methods;
90+
const auto &methods =
91+
java_class_loader.get_original_class(class_name).parsed_class.methods;
9292
for(const auto &method : methods)
9393
{
94-
const irep_idt methodid="java::"+id2string(classname)+"."+
95-
id2string(method.name)+":"+
96-
id2string(method.descriptor);
94+
const irep_idt methodid =
95+
"java::" + id2string(class_name) + "." + id2string(method.name)
96+
+ ":" + id2string(method.descriptor);
9797
method_worklist2.push_back(methodid);
9898
}
9999
}

0 commit comments

Comments
 (0)