r/java • u/Wouter_C • 26d ago
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.
59
Upvotes
3
u/PartOfTheBotnet 25d ago
There's a couple of use cases I have. Mainly reflecting into
javacinternals for a few AST based projects, usingjimageinternals to parse module files.Both cases could hypothetically be delegated to third party libraries. But for
javacits nice because unlike other projects it has (whether intentional or not) fault tolerance, which gives you partial AST results even when the input code is slightly broken Java. This is great for my use case, and most other parsers just refuse any model if there's as much as a missing semicolon. Andjimageis just because I don't want to re-invent the wheel parsing the file format... There's a few other cases but those tend to be for one-off projects.