puniverse / quasar

Fibers, Channels and Actors for the JVM
http://docs.paralleluniverse.co/quasar/
Other
4.56k stars 575 forks source link

do you forget something in co.paralleluniverse.common.util.UtilUnsafe class? #345

Open mashirofang opened 3 years ago

mashirofang commented 3 years ago
  public static Unsafe getUnsafe() {
        try {
            return Unsafe.getUnsafe();
        } catch (SecurityException se) {
            try {
                return java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction<Unsafe>() {
                    @Override
                    public Unsafe run() throws Exception {
                        final Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
                        if (true) {
                            final Field f = k.getDeclaredField("theUnsafe");
                            f.setAccessible(true);
                            final Object x = f.get(null);
                            return k.cast(x);
                        } else {
                            for (Field f : k.getDeclaredFields()) {
                                f.setAccessible(true);
                                final Object x = f.get(null);
                                if (k.isInstance(x))
                                    return k.cast(x);
                            }
                            throw new NoSuchFieldError("the Unsafe");
                        }
                    }
                });
            } catch (java.security.PrivilegedActionException e) {
                throw new RuntimeException("Could not initialize intrinsics", e.getCause());
            }
        }
    }

why would you use "if(true) .... else ..." in this method? do you forget to fill the expression of if?