BCEL == monkeypatching for java?

a colleague pointed me the other day to BCEL , which, as far as I can tell from its explanation and quick reading, is a way to change while the byte code is being executed. At first I thought it sounds dangerous, and I thought it sounds cool. Then I thought a little more and I remembered the codinghorror message about fixing monkeys and realized that it was basically the same. Has anyone ever used BCEL for something practical? Is it right that this is a monkey fix at runtime, or am I missing something?

+3
source share
5 answers

This is a bit lower level than the classic monkey patch, and from what I read, classes already loaded into the virtual machine are not updated. It only supports saving it in class files, without changing the runtime classes.

+1
source

From the BCEL FAQ:

Q: Can I create or modify classes? dynamically with BCEL?

A: BCEL contains useful classes in, namely ClassLoader and JavaWrapper. Take a look at the ProxyCreator Example.

But monkeypatching is ... uhm ... inconsistent, and you probably shouldn't use it if your language doesn't support it.

If you have a good use case, can I suggest implementing Jython?

+3
source

. (, ), ( , Spring Hibenrate ).

0

: Jawk - . BCEL "".

0

BCEL , - , , . monkeypatching JVM, , ​​ BCEL Java. Java ( -javaagent) API- . .

:

  • , javaagent.
  • .
  • You can change the method. Theoretically, you can also add some method, but you need to compile the project with the modified (fixed) classes. I think it would cause a lot of pain, and it's not worth it. There are alternative languages ​​that support it (e.g. Groovy) or support something similar (e.g. implicit conversions in Scala).
  • It's better to design your API than using a monkey patch. This may be useful for third-party libraries.
0
source

Source: https://habr.com/ru/post/1696661/


All Articles