75 case AccessFlags flags when location == TestLocation.CLASS -> cb
76 .withFlags(flags.flagsMask() | ACC_PRIVATE);
77 case FieldModel f when location == TestLocation.FIELD -> cb
78 .transformField(f, (fb, fe) -> {
79 if (fe instanceof AccessFlags flags) {
80 fb.withFlags(flags.flagsMask() | ACC_SYNCHRONIZED);
81 } else {
82 fb.with(fe);
83 }
84 });
85 case MethodModel m when location == TestLocation.METHOD -> cb
86 .transformMethod(m, (mb, me) -> {
87 if (me instanceof AccessFlags flags) {
88 mb.withFlags(flags.flagsMask() | ACC_INTERFACE);
89 } else {
90 mb.with(me);
91 }
92 });
93 case InnerClassesAttribute attr when location == TestLocation.INNER_CLASS -> cb
94 .with(InnerClassesAttribute.of(attr.classes().stream()
95 .map(ic -> InnerClassInfo.of(ic.innerClass(), ic.outerClass(), ic.innerName(), ic.flagsMask() | 0x0020))
96 .toList()));
97 default -> cb.with(ce);
98 }
99 });
100
101 Files.write(Path.of("transformed.class"), bytes);
102
103 var lines = new JavapTask(toolBox)
104 .classes("transformed.class")
105 .options("-c", "-p", "-v")
106 .run(location.fails ? Task.Expect.FAIL : Task.Expect.SUCCESS)
107 .writeAll()
108 .getOutputLines(Task.OutputKind.DIRECT);
109
110 // No termination when access flag error happens
111 assertTrue(lines.stream().anyMatch(l -> l.contains("java.lang.String field;")));
112 assertTrue(lines.stream().anyMatch(l -> l.contains("UndefinedAccessFlagTest$SampleInnerClass();")));
113 assertTrue(lines.stream().anyMatch(l -> l.contains("void method();")));
114 assertTrue(lines.stream().anyMatch(l -> l.contains("SampleInnerClass=class UndefinedAccessFlagTest$SampleInnerClass of class UndefinedAccessFlagTest")));
115
|
75 case AccessFlags flags when location == TestLocation.CLASS -> cb
76 .withFlags(flags.flagsMask() | ACC_PRIVATE);
77 case FieldModel f when location == TestLocation.FIELD -> cb
78 .transformField(f, (fb, fe) -> {
79 if (fe instanceof AccessFlags flags) {
80 fb.withFlags(flags.flagsMask() | ACC_SYNCHRONIZED);
81 } else {
82 fb.with(fe);
83 }
84 });
85 case MethodModel m when location == TestLocation.METHOD -> cb
86 .transformMethod(m, (mb, me) -> {
87 if (me instanceof AccessFlags flags) {
88 mb.withFlags(flags.flagsMask() | ACC_INTERFACE);
89 } else {
90 mb.with(me);
91 }
92 });
93 case InnerClassesAttribute attr when location == TestLocation.INNER_CLASS -> cb
94 .with(InnerClassesAttribute.of(attr.classes().stream()
95 .map(ic -> InnerClassInfo.of(ic.innerClass(), ic.outerClass(), ic.innerName(), ic.flagsMask() | 0x0050))
96 .toList()));
97 default -> cb.with(ce);
98 }
99 });
100
101 Files.write(Path.of("transformed.class"), bytes);
102
103 var lines = new JavapTask(toolBox)
104 .classes("transformed.class")
105 .options("-c", "-p", "-v")
106 .run(location.fails ? Task.Expect.FAIL : Task.Expect.SUCCESS)
107 .writeAll()
108 .getOutputLines(Task.OutputKind.DIRECT);
109
110 // No termination when access flag error happens
111 assertTrue(lines.stream().anyMatch(l -> l.contains("java.lang.String field;")));
112 assertTrue(lines.stream().anyMatch(l -> l.contains("UndefinedAccessFlagTest$SampleInnerClass();")));
113 assertTrue(lines.stream().anyMatch(l -> l.contains("void method();")));
114 assertTrue(lines.stream().anyMatch(l -> l.contains("SampleInnerClass=class UndefinedAccessFlagTest$SampleInnerClass of class UndefinedAccessFlagTest")));
115
|