Created
October 31, 2012 17:41
-
-
Save nitsanw/3988577 to your computer and use it in GitHub Desktop.
Using Unsafe to break encapsulation - step 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final Unsafe unsafe; | |
static | |
{ | |
try | |
{ | |
// This is a bit of voodoo to force the unsafe object into | |
// visibility and acquire it. | |
// This is not playing nice, but as an established back door it is | |
// not likely to be taken away. | |
Field field = Unsafe.class.getDeclaredField("theUnsafe"); | |
field.setAccessible(true); | |
unsafe = (Unsafe)field.get(null); | |
} | |
catch (Exception e) | |
{ | |
throw new RuntimeException(e); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for the blog post here: http://psy-lob-saw.blogspot.co.uk/2012/10/breaking-string-encapsulation-using.html