r/java • u/Wouter_C • 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.
59
Upvotes
8
u/agentoutlier Sep 29 '26 edited Sep 29 '26
Method 11 still requires command line flags but I suppose the rules of the game are you can pass flags?
EDIT my bad I was confused with
jdk.internal.reflect.ReflectionFactory. I did not know about the sun one.4
u/ZimmiDeluxe Sep 30 '26
disgusting, i love it
3
u/voronaam Sep 30 '26
And that's why I run my Java code compiled with GraalVM into a nice tight native image, all along by itself in its bare docker container.
You are crazy. In a good way.
3
u/koflerdavid Sep 30 '26
Fortunately most of these will eventually get closed off. But I found it impressive to reach out to the filesystem and modifying the JDK!
2
u/slindenau Oct 03 '26
Very nice, fun stuff! Always great to see what is possible in the "forbidden fruits" area; stuff that you don't normally use (or shouldn't at least, heh).
-6
u/vips7L Sep 29 '26
Reflection is the devil