How to check code length for Hibernate proxy?

Gabriel Robaina :

I am writing an application that writes java code from some database information. I am suffering from a MethodTooLargeException when byte-buddy checks the code's length of a Hibernate Proxy made on a big class of mine.

Please correct me if I am wrong: From what I know, Hibernate creates a proxy class dynamically, based on my class. This Hibernate Proxy class is larger, in terms of code length, than the original class.

I want to be able to check the code's length of the class that will be generated (by byte-buddy + Hibernate Proxy) to prevent my application from writing classes that would cause a runtime exception when code's length is bigger than 65535 bytes.

In this case, my class EeWmo has a code length bigger than the limit when proxied with Hibernate, and thats why a runtime exception happens.

How can I deal with this situation? Any insights will be very helpful.

Thank you.

case

Rafael Winterhalter :

To avoid a performance overhead for the most likely case, the method length is not precomputed. The proxy will instrument any field access to add dirty flags and I do not think that there is a way to avoid this problem. One could theoretically move some of the code to another method but I think this would not be intuitive since it alters the stack trace and it is neither a very common scenario.

I'd suggest to you to refactor your code and to split some of the long method. Alternatively, you can skip instrumentation for the classes in question.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=153833&siteId=1