Guest User

Untitled

a guest
Mar 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. public static Class<?> getKlass2(){
  2. String className = "TestClass";
  3. ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
  4.  
  5. classWriter.visit(V1_8, ACC_PUBLIC, className, null, getInternalName(Object.class), null);
  6.  
  7. MethodVisitor mv = classWriter.visitMethod(ACC_PUBLIC + ACC_STATIC, "m", "()Z",null, null);
  8. Label trueLable = new Label();
  9. Label afterFalseLable = new Label();
  10. mv.visitFieldInsn(GETSTATIC, getInternalName(Boolean.class), "TRUE", "Ljava/lang/Boolean;");
  11. mv.visitMethodInsn(INVOKEVIRTUAL, getInternalName(Boolean.class), "booleanValue", "()Z", false);
  12. mv.visitJumpInsn(IFEQ, trueLable);
  13. mv.visitInsn(ICONST_1);
  14. mv.visitJumpInsn(GOTO, afterFalseLable);
  15. mv.visitLabel(trueLable);
  16. mv.visitInsn(ICONST_0);
  17. mv.visitFrame(F_APPEND, 0, null, 0, null);
  18. mv.visitLabel(afterFalseLable);
  19. mv.visitInsn(IRETURN);
  20. mv.visitMaxs(1, 1);
  21. mv.visitEnd();
  22. //converting classWriter.toByteArray() to Class<?> instance
  23. }
  24.  
  25. Expecting a stackmap frame at branch target 13
  26.  
  27. Exception Details:
  28. Location:
  29. TestClass.m()Z @6: ifeq
  30. Reason:
  31. Expected stackmap frame at this location.
  32. Bytecode:
  33. 0x0000000: b200 0cb6 000f 9900 0704 a700 0403 ac
  34. Stackmap Table:
  35. same_frame_extended(@14)
  36.  
  37. public class TestClass {
  38. public static boolean m();
  39. Code:
  40. 0: getstatic #12 // Field java/lang/Boolean.TRUE:Ljava/lang/Boolean;
  41. 3: invokevirtual #15 // Method java/lang/Boolean.booleanValue:()Z
  42. 6: ifeq 13
  43. 9: iconst_1
  44. 10: goto 14
  45. 13: iconst_0
  46. 14: ireturn
  47. }
  48.  
  49. mv.visitFrame(F_APPEND, 0, new Object[]{ }, 0, new Object[]{ });
Add Comment
Please, Sign In to add comment