Question

Is it possible to inherit a final class using bytecode manipulations?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top