Skip to content

Commit b77b5b0

Browse files
Merge pull request diffblue#4571 from thomasspriggs/tas/java_synthetic
Parse and convert the synthetic flag of java methods
2 parents 176c960 + d706767 commit b77b5b0

8 files changed

+61
-1
lines changed

jbmc/src/java_bytecode/java_bytecode_convert_method.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ void java_bytecode_convert_method_lazy(
343343
member_type.set(ID_is_static, true);
344344
member_type.set_native(m.is_native);
345345
member_type.set_is_varargs(m.is_varargs);
346+
member_type.set_is_synthetic(m.is_synthetic);
346347

347348
if(m.is_bridge)
348349
member_type.set(ID_is_bridge_method, m.is_bridge);

jbmc/src/java_bytecode/java_bytecode_parse_tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ struct java_bytecode_parse_treet
8585
{
8686
irep_idt base_name;
8787
bool is_native = false, is_abstract = false, is_synchronized = false,
88-
is_bridge = false, is_varargs = false;
88+
is_bridge = false, is_varargs = false, is_synthetic = false;
8989
source_locationt source_location;
9090

9191
typedef std::vector<instructiont> instructionst;

jbmc/src/java_bytecode/java_bytecode_parser.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1864,6 +1864,7 @@ void java_bytecode_parsert::rmethod(classt &parsed_class)
18641864
method.is_native=(access_flags&ACC_NATIVE)!=0;
18651865
method.is_bridge = (access_flags & ACC_BRIDGE) != 0;
18661866
method.is_varargs = (access_flags & ACC_VARARGS) != 0;
1867+
method.is_synthetic = (access_flags & ACC_SYNTHETIC) != 0;
18671868
method.name=pool_entry(name_index).s;
18681869
method.base_name=pool_entry(name_index).s;
18691870
method.descriptor=id2string(pool_entry(descriptor_index).s);

jbmc/src/java_bytecode/java_types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,16 @@ class java_method_typet : public code_typet
418418
{
419419
set(ID_is_varargs_method, is_varargs);
420420
}
421+
422+
bool is_synthetic() const
423+
{
424+
return get_bool(ID_synthetic);
425+
}
426+
427+
void set_is_synthetic(bool is_synthetic)
428+
{
429+
set(ID_synthetic, is_synthetic);
430+
}
421431
};
422432

423433
template <>
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class ClassWithSyntheticMethod {
2+
private static int inaccessible() {
3+
return 42;
4+
}
5+
6+
public class Inner {
7+
public int access() {
8+
return inaccessible();
9+
}
10+
}
11+
}

jbmc/unit/java_bytecode/java_bytecode_convert_method/convert_method.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,40 @@ SCENARIO(
249249
}
250250
}
251251
}
252+
253+
SCENARIO(
254+
"java_bytecode_convert_synthetic_method",
255+
"[core][java_bytecode][java_bytecode_convert_method]")
256+
{
257+
GIVEN("A class with a synthetic method.")
258+
{
259+
const symbol_tablet symbol_table = load_java_class(
260+
"ClassWithSyntheticMethod",
261+
"./java_bytecode/java_bytecode_convert_method");
262+
263+
WHEN("Parsing a synthetic method.")
264+
{
265+
const java_method_typet *const synthetic_method =
266+
type_try_dynamic_cast<java_method_typet>(symbol_table.lookup_ref(
267+
"java::ClassWithSyntheticMethod.access$000:()I").type);
268+
REQUIRE(synthetic_method);
269+
270+
THEN("The method should be marked as synthetic.")
271+
{
272+
REQUIRE(synthetic_method->is_synthetic());
273+
}
274+
}
275+
WHEN("Parsing a non synthetic method.")
276+
{
277+
const java_method_typet *const non_synthetic_method =
278+
type_try_dynamic_cast<java_method_typet>(symbol_table.lookup_ref(
279+
"java::ClassWithSyntheticMethod.inaccessible:()I").type);
280+
REQUIRE(non_synthetic_method);
281+
282+
THEN("The method should not be marked as synthetic.")
283+
{
284+
REQUIRE(!non_synthetic_method->is_synthetic());
285+
}
286+
}
287+
}
288+
}

0 commit comments

Comments
 (0)