Skip to content

Commit ed39db2

Browse files
Adds another test for deeply nested classes.
This tests when the containing class is private.
1 parent 4c20b21 commit ed39db2

9 files changed

+112
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

jbmc/unit/java_bytecode/java_bytecode_parser/InnerClasses.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,39 @@ private PrivateDoublyNestedInnerClass(int i) {
8585
}
8686
}
8787

88+
class InnerPrivateClassesDeeplyNested {
89+
private class SinglyNestedPrivateClass {
90+
int i;
91+
SinglyNestedPrivateClass(int i) {
92+
this.i = i;
93+
}
94+
public class PublicDoublyNestedInnerClass {
95+
public int i;
96+
public PublicDoublyNestedInnerClass(int i) {
97+
this.i = i;
98+
}
99+
}
100+
class DefaultDoublyNestedInnerClass {
101+
int i;
102+
DefaultDoublyNestedInnerClass(int i) {
103+
this.i = i;
104+
}
105+
}
106+
protected class ProtectedDoublyNestedInnerClass {
107+
protected int i;
108+
protected ProtectedDoublyNestedInnerClass(int i) {
109+
this.i = i;
110+
}
111+
}
112+
private class PrivateDoublyNestedInnerClass {
113+
private int i;
114+
private PrivateDoublyNestedInnerClass(int i) {
115+
this.i = i;
116+
}
117+
}
118+
}
119+
}
120+
88121
class ContainsAnonymousClass {
89122
interface InnerInterface {
90123
int i = 0;

jbmc/unit/java_bytecode/java_bytecode_parser/parse_java_attributes.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,85 @@ SCENARIO(
216216
}
217217
}
218218

219+
GIVEN(
220+
"Some package-private class files in the class path with private deeply"
221+
"nested inner classes")
222+
{
223+
const symbol_tablet &new_symbol_table = load_java_class(
224+
"InnerPrivateClassesDeeplyNested",
225+
"./java_bytecode/java_bytecode_parser");
226+
WHEN(
227+
"Parsing the InnerClasses attribute for a public doubly-nested inner "
228+
"class")
229+
{
230+
THEN(
231+
"The inner class should be marked as private because its containing "
232+
"class has stricter access ")
233+
{
234+
const symbolt &class_symbol = new_symbol_table.lookup_ref(
235+
"java::InnerPrivateClassesDeeplyNested$SinglyNestedPrivateClass$"
236+
"PublicDoublyNestedInnerClass");
237+
const java_class_typet java_class =
238+
to_java_class_type(class_symbol.type);
239+
REQUIRE_FALSE(java_class.get_is_anonymous_class());
240+
REQUIRE(java_class.get_is_inner_class());
241+
REQUIRE(java_class.get_access() == ID_private);
242+
}
243+
}
244+
WHEN(
245+
"Parsing the InnerClasses attribute for a package private doubly-nested "
246+
"inner class")
247+
{
248+
THEN(
249+
"The inner class should be marked as private because its containing "
250+
"class has stricter access ")
251+
{
252+
const symbolt &class_symbol = new_symbol_table.lookup_ref(
253+
"java::InnerPrivateClassesDeeplyNested$SinglyNestedPrivateClass$"
254+
"DefaultDoublyNestedInnerClass");
255+
const java_class_typet java_class =
256+
to_java_class_type(class_symbol.type);
257+
REQUIRE_FALSE(java_class.get_is_anonymous_class());
258+
REQUIRE(java_class.get_is_inner_class());
259+
REQUIRE(java_class.get_access() == ID_private);
260+
}
261+
}
262+
WHEN(
263+
"Parsing the InnerClasses attribute for a protected doubly-nested inner "
264+
"class")
265+
{
266+
THEN(
267+
"The inner class should be marked as private because its containing "
268+
"class has stricter access ")
269+
{
270+
const symbolt &class_symbol = new_symbol_table.lookup_ref(
271+
"java::InnerPrivateClassesDeeplyNested$SinglyNestedPrivateClass$"
272+
"ProtectedDoublyNestedInnerClass");
273+
const java_class_typet java_class =
274+
to_java_class_type(class_symbol.type);
275+
REQUIRE_FALSE(java_class.get_is_anonymous_class());
276+
REQUIRE(java_class.get_is_inner_class());
277+
REQUIRE(java_class.get_access() == ID_private);
278+
}
279+
}
280+
WHEN(
281+
"Parsing the InnerClasses attribute for a private doubly-nested inner "
282+
"class")
283+
{
284+
THEN("The inner class should be marked as private ")
285+
{
286+
const symbolt &class_symbol = new_symbol_table.lookup_ref(
287+
"java::InnerPrivateClassesDeeplyNested$SinglyNestedPrivateClass$"
288+
"PrivateDoublyNestedInnerClass");
289+
const java_class_typet java_class =
290+
to_java_class_type(class_symbol.type);
291+
REQUIRE_FALSE(java_class.get_is_anonymous_class());
292+
REQUIRE(java_class.get_is_inner_class());
293+
REQUIRE(java_class.get_access() == ID_private);
294+
}
295+
}
296+
}
297+
219298
GIVEN(
220299
"Some package-private class files in the class path with anonymous classes")
221300
{

0 commit comments

Comments
 (0)