/*
 * This file is part of sprintj, licensed under the MIT License (MIT).
 *
 * Copyright (c) 2014 Oliver Stanley <http://ollie.pw>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package pw.ollie.sprint.reflect.sun;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * Provides access to {@link sun.misc.Unsafe}. Should only be used in very rare
 * circumstances, and only when you understand what you are doing and the
 * connotations of messing with it. Improper usage of {@link sun.misc.Unsafe}
 * <em>WILL</em> crash the JVM.
 *
 * @author Ollie [DziNeIT]
 */
public class UnsafeAccessor {
    /**
     * An iterate of possible field names for the instance of {@link Unsafe}. This
     * is used because on different JVMs, the field name for {@link Unsafe}'s
     * instance may be different - for example, on Dalvik the field name is
     * THE_ONE, but on the Hotspot JVM, the field is {@link Unsafe#theUnsafe}.
     */
    private static final String[] FIELD_NAMES = {
            "theUnsafe", // Oracle JVM
            "THE_ONE" // Dalvik JVM
    };

    /**
     * The {@link sun.misc.Unsafe} instance. Do not use this unless you know
     * what you are doing. Improper usage of this class <em>WILL</em> crash the
     * JVM.
     */
    private static Unsafe unsafe = null;
    /**
     * Whether we have already failed to get the {@link sun.misc.Unsafe}
     * instance. If true, {@code null} will always be returned by {@link #get()}
     * - otherwise {@link #get()} will attempt to acquire the instance if it
     * has not already been acquired.
     */
    private static boolean failed = false;

    /**
     * Gets the instance of {@link sun.misc.Unsafe}. Will attempt to retrieve
     * the instance via reflection if it is possible - if the field cannot be
     * retrieved, {@code null} <em>WILL</em> be returned.
     *
     * You should not use {@link sun.misc.Unsafe} unless you <em>REALLY</em>
     * know what you are doing and understand the connotations of messing with
     * the class. Improper usage <em>WILL</em> crash the JVM.
     *
     * @return the {@link sun.misc.Unsafe} instance, or null if not available
     */
    public static Unsafe get() {
        if (unsafe == null && !failed) {
            for (String fieldName : FIELD_NAMES) {
                try {
                    Field field = Unsafe.class.getDeclaredField(fieldName);
                    field.setAccessible(true);
                    unsafe = (Unsafe) field.get(null);
                } catch (Exception ignore) {
                }
            }

            if (unsafe == null) {
                failed = true;
                return null;
            }
        }

        return unsafe;
    }
}

@@ -3248,20 +3248,19 @@
 afe 
-=
+!
 = null 
-&& !
+%7C%7C 
 fail
@@ -3261,32 +3261,66 @@
 %7C failed) %7B%0A    
+        return unsafe;%0A        %7D%0A%0A
         for (Str
@@ -3346,28 +3346,24 @@
 LD_NAMES) %7B%0A
-    
             
@@ -3384,20 +3384,16 @@
         
-    
 Field fi
@@ -3436,28 +3436,24 @@
 fieldName);%0A
-    
             
@@ -3499,20 +3499,16 @@
         
-    
 unsafe =
@@ -3546,20 +3546,16 @@
         
-   
- 
 %7D catch 
@@ -3591,25 +3591,18 @@
     
-    %7D%0A   
+%7D%0A
         
  %7D%0A%0A
@@ -3593,32 +3593,27 @@
   %7D%0A        
- 
 %7D%0A%0A
-    
         if (
@@ -3642,20 +3642,16 @@
         
-  
-  
 failed =
@@ -3661,51 +3661,8 @@
 ue;%0A
-                return null;%0A            %7D%0A
     

Make UnsafeAccessor#get() look nicer