0

I am using byte buddy to print logs of methods automaticly,but i found that if i use byte buddy to regenerate class files,the LocalVariableTable will be overwritten and disappear.and that will make springmvc unfunctional because springmvc uses LocalVariableTable to get the names of args of methods,and if there is no LocalVariableTable, the programme will go wrong.so how can byte buddy generate a class file with LocalVariableTable? here is how I used it:

DynamicType.Builder<?>.method((isPublic()
                       .and(not(isEquals()))
                       .and(not(isClone()))
                       .and(not(isToString()))
                       .and(not(isHashCode()))
                       .and(not(isDefaultMethod()))
                       .and(not(isDefaultConstructor()))
                       .and(not(isDefaultFinalizer()))
                       .and(not(isAbstract()))
                       .and(not(isStatic()))
                       .and(not(isSetter().or(isGetter()))))
                               .or(isAnnotatedWith(Hook.class)))
                       .intercept(Advice.to(MethodHooks.class));
Tarn_
  • 1
  • 1
  • How are you creating the methods? If you use `defineMethod("test", int.class, Modifier.PUBLIC).withParameter(String.class, "paramName")` the name of the parameter is available. – k5_ Jun 09 '20 at 21:10
  • Hi k5_, thanks for commenting.I didn't use defineMethod("test", int.class, Modifier.PUBLIC).withParameter(String.class, "paramName") to create methods, I am using byte buddy to print log info before and after orginal methods without modtifying the original codes.because my project is built by SpringMVC, and If i use bytebuddy to recompile the original classes, LocalVariableTable will be disappear,and springMVC's annotation @RequestParam needs it to match paraments,so I am asking if there's a way to retain class's LocalVariableTable when recompiling classes. – Tarn_ Jun 10 '20 at 02:40

1 Answers1

0

If you use interception, you are defining a new method and the old method is backed-up to another location for being able to invoke it. This includes the debug table where this information is stored. You can however compile a class using the -parameters parameter. This more official information is retained by Byte Buddy.

Rafael Winterhalter
  • 42,759
  • 13
  • 108
  • 192