Safely Shoot Yourself in the Foot with Java 9
summary
Java 9 removes easy Unsafe access but still allows the same attacks using VarHandles and MethodHandles.privateLookupIn to mutate String byte[] internals and bypass final-field protections; unchecked checked exceptions still appear via Unsafe hacks. Direct ByteBuffer unmapping uses Unsafe.invokeCleaner instead of phantom-cleaner tricks and works but is unsafe. Module flags like --add-exports and -XX:RestrictContended are needed to access @Contended and hidden internals. jshell and stream ops takeWhile/dropWhile ship but parallel semantics can break.
AI-written summary · about
chapters (12)
- 0:00Introduction and Java 9 overview
- 2:14Security improvements in Java 9
- 6:06Unsafe class and its risks
- 10:41VarHandles replacing Unsafe
- 14:12New ways to shoot yourself in the foot
- 25:29Modifying private fields with VarHandles
- 33:16Unmapping memory buffers in Java 9
- 41:51Cleaner API and direct buffers
- 45:04Contended annotation and modules
- 47:55New stream features and JShell
- 50:47JShell for beginners and scripting
- 55:29Garbage collection changes in Java 9
