Is it possible to somehow inherit the last class modifying the bytecode?

Is it possible to inherit the final class using bytecode manipulation?

+6
source share
2 answers

Yes and no.

You can use bytecode manipulation to change the final class to final on the fly. This does not even violate binary compatibility, so there is no risk of loader / class verification errors.

However, you must apply the bytecode modifications to the final class itself. You cannot manipulate bytecode in a child class to inherit it from the final parent class. More precisely, if you make the modified child class be rejected by the verifier when loading along with the final class.

+4
source

This describes the class file format. At offset 10+cpsize there are 2 bytes defining the access flags of this class. One of these flags is called ACC_FINAL (0x0010) . I suppose you can mask this bit and make this class not the last.

0
source

All Articles