Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mashirofang opened this issue Nov 4, 2020 · 0 comments

Comments

@mashirofang
Copy link

  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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant