Sun.misc.Unsafe



  • So, I know that with some of the more absurd restrictions Java imposes on developers (coughgenericscough), you sometimes might get the feeling you're actually playing an intricate puzzle game. What I didn't know so far is that it had cheats.

    (Disclaimer: I just stumbled about this while trying to find some other classes. Sorry if this is common knowledge. I just found it funny.)



  • Every time I have to play the Java puzzle game I always end up feeling that I'm missing a few of the pieces. Java is about as expressive as english would be without adjectives.

     

    for some reason that class brings memories of the ancient native APIs that were available years ago- J/Direct, JNI, and so forth. shudders



  • So it's like... C implemented in Java implemented in C.

    Mind mind = new EnterpriseSuctionFactory().getInstanceFacade().getInstance().getSuction().invert();



  • So... what's the WTF? It's an internal, undocumented helper for performing unsafe operations.



  • Interesting find. java.util.Random modifies its final seed field this way. Why call seed.set() or remove the final modifier when you can abuse the JVM instead?



  • @fatbull said:

    Interesting find. java.util.Random modifies its final seed field this way.

    I admit I don't have much of a clue about Java, but what in the world is this good for?
    catch (Exception ex) { throw new Error(ex); }



  • @derula said:

    I admit I don't have much of a clue about Java, but what in the world is this good for?
    catch (Exception ex) { throw new Error(ex); }
     

    Normal Java apps don't catch Errors; this code basically turns standard Exceptions into something-really-bad-happened-internally-dont-try-to-catch-us Errors.



  •  I've worked with a library which used Unsafe to implement custom deserialisation. It worked, you can say that much for it.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.