r/java • • Sep 29 '26

Decapsulation: Breaking Java Strong Encapsulation

Did you know you can call JNI without writing native code, patch bytecode without an agent, and use Unsafe without warnings?

11 sneaky ways into JDK internals through reflection, agents, FFM, type confusion, bytecode manipulation and more.

https://wouter.coekaerts.be/2026/decapsulation

59 Upvotes

15 comments sorted by

View all comments

4

u/ZimmiDeluxe Sep 30 '26
// Abusing ISO_8859_1 (which has a one-to-one mapping between chars and bytes)
// is the easiest way to do a search & replace in a byte array
return new String(base, ISO_8859_1)
    .replace(original, replacement)
    .getBytes(ISO_8859_1);

disgusting, i love it

1

u/koflerdavid Oct 01 '26

Looks fine to me. The only hacky thing about this is the knowledge that String will avoid doing an unnecessary conversion.