Skip to content

Instantly share code, notes, and snippets.

@nitsanw
Created October 31, 2012 17:41
Show Gist options
  • Save nitsanw/3988577 to your computer and use it in GitHub Desktop.
Save nitsanw/3988577 to your computer and use it in GitHub Desktop.
Using Unsafe to break encapsulation - step 1
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);
}
}
@nitsanw
Copy link
Author

nitsanw commented Nov 1, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment