Reputation: 105043
Is it possible to inherit a final class using bytecode manipulations?
Upvotes: 8
Views: 657
Reputation: 718678
Yes and no.
You can use bytecode manipulation to change a final
class to non-final
on the fly. This doesn't even break binary compatibility, so there is no risk of class loader / verifier errors.
However, you have to apply the bytecode modifications to the final
class itself. You can't do bytecode manipulation on a child class to make it inherit from a final
parent class. Or more precisely, if you do that the modified child class will be rejected by the verifier when loaded together with the final
parent class.
Upvotes: 4
Reputation: 29213
This describes the class file format. At the 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 that bit out and make that class non-final.
Upvotes: 0