}
@Test
public void jlClass_getModifiers() throws Exception {
byte[] classbytes = loadBytesForClass("system.Eight");
RewriteResult rr = SystemClassReflectionRewriter.rewrite("system.Eight", classbytes);
byte[] newbytes = rr.bytes;
Class<?> clazz = loadit("system.Eight", newbytes);
// Check the new field and method are in the type:
//@formatter:off
assertEquals(
"CLASS: system/Eight v50 0x0021(public synchronized) super java/lang/Object\n"+
"SOURCE: Eight.java null\n"+
"INNERCLASS: system/Eight$Inner system/Eight Inner 2\n"+
"FIELD 0x0009(public static) __sljlcgmods Ljava/lang/reflect/Method;\n"+
"METHOD: 0x0001(public) <init>()V\n"+
"METHOD: 0x0001(public) <init>(Ljava/lang/String;)V\n"+
"METHOD: 0x0001(public) runIt()Ljava/lang/String; java/lang/Exception\n"+
"METHOD: 0x0001(public) m(Ljava/lang/Class;)I\n"+
"METHOD: 0x000a(private static) __sljlcgmods(Ljava/lang/Class;)I\n"+
"\n",
toStringClass(newbytes));
//@formatter:on
Object value = run(clazz, "runIt");
// Check that without the field initialized, things behave as expected
assertEquals("complete:mods?1 mods?0 mods?2", value);
assertEquals(0, callcount);
// Set the field
Method m = SystemClassReflectionRewriterTests.class.getDeclaredMethod("helper6", Class.class);
// m = ReflectiveInterceptor.class.getDeclaredMethod("jlClassGetDeclaredField", Class.class, String.class);
assertNotNull(m);
clazz.getDeclaredField(jlcgmods).set(null, m);
// Now re-run, should be intercepted to call our helper
value = run(clazz, "runIt");
assertEquals("complete:mods?1 mods?0 mods?2", value);
// Check the correct amount of rewriting went on
assertTrue((rr.bits & JLC_GETMODIFIERS) != 0);
assertTrue((rr.bits & ~JLC_GETMODIFIERS) == 0);
assertEquals(3, callcount);
assertEquals(3, events.size());
assertEquals("helper6(system.Eight)", events.get(0));
assertEquals("helper6(system.DefaultVis)", events.get(1));
assertEquals("helper6(system.Eight$Inner)", events.get(2));
assertEquals("Class.getModifiers()", rr.summarize());
}