@Override public sun.misc.Unsafe run() throws Exception { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (java.lang.reflect.Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { return k.cast(x); } } throw new NoSuchFieldError("the Unsafe"); } });
@Override public sun.misc.Unsafe run() throws Exception { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (java.lang.reflect.Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { return k.cast(x); } } throw new NoSuchFieldError("the Unsafe"); } });
public Field run() { try { return clazz.getDeclaredField(name); } catch (NoSuchFieldException e) { throw new NoSuchFieldError(e.getMessage()); } } }
@Override public sun.misc.Unsafe run() throws Exception { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (java.lang.reflect.Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { return k.cast(x); } } throw new NoSuchFieldError("the Unsafe"); } });
public Field run() { final Field field; try { field = clazz.getDeclaredField(fieldName); } catch (NoSuchFieldException e) { throw new NoSuchFieldError(e.getMessage()); } field.setAccessible(true); return field; } }
public Unsafe run() { try { final Field field = Unsafe.class.getDeclaredField("theUnsafe"); field.setAccessible(true); return (Unsafe) field.get(null); } catch (IllegalAccessException e) { throw new IllegalAccessError(e.getMessage()); } catch (NoSuchFieldException e) { throw new NoSuchFieldError(e.getMessage()); } } });
@Override public sun.misc.Unsafe run() throws Exception { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (java.lang.reflect.Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { return k.cast(x); } } throw new NoSuchFieldError("the Unsafe"); } });
public Field[] getEnumConstants(Class clazz) { try { Object[] values = clazz.getEnumConstants(); Field[] fields = new Field[values.length]; for (int i = 0; i < values.length; i++) { fields[i] = clazz.getField(((Enum) values[i]).name()); } return fields; } catch (NoSuchFieldException e) { // impossible throw new NoSuchFieldError(e.getMessage()); } }
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) { try { return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); } catch (NoSuchFieldException e) { // Convert Exception to corresponding Error NoSuchFieldError error = new NoSuchFieldError(field); error.initCause(e); throw error; } } }
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) { try { return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); } catch (NoSuchFieldException e) { // Convert Exception to corresponding Error NoSuchFieldError error = new NoSuchFieldError(field); error.initCause(e); throw error; } } }
static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) { try { return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field)); } catch (NoSuchFieldException e) { // Convert Exception to corresponding Error NoSuchFieldError error = new NoSuchFieldError(field); error.initCause(e); throw error; } }
/** * Finds a field on the given type for the given name. * * @param type The type * @param name The name * @return An {@link Optional} contains the method or empty */ public static Field getRequiredField(Class type, String name) { try { return type.getDeclaredField(name); } catch (NoSuchFieldException e) { Optional<Field> field = findField(type, name); return field.orElseThrow(() -> new NoSuchFieldError("No field '" + name + "' found for type: " + type.getName())); } }
static sun.misc.Unsafe getUnsafe() { try { return sun.misc.Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { return java.security.AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> { Class<Unsafe> k = Unsafe.class; for (Field f : k.getDeclaredFields()) { f.setAccessible(true); 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()); } } }
static sun.misc.Unsafe getUnsafe() { try { return sun.misc.Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { } try { return java.security.AccessController.doPrivileged((PrivilegedExceptionAction<Unsafe>) () -> { Class<Unsafe> k = Unsafe.class; for (Field f : k.getDeclaredFields()) { f.setAccessible(true); 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()); } } }
static Unsafe getSMU() { try { return sun.misc.Unsafe.getUnsafe(); } catch (SecurityException tryReflectionInstead) { // ignore } try { return java.security.AccessController.doPrivileged ((PrivilegedExceptionAction<Unsafe>) () -> { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (Field f : k.getDeclaredFields()) { f.setAccessible(true); 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()); } }
Field field = classDesc.getSuperclass().getReflectionField(fields[1]); if (field == null) { throw new NoSuchFieldError();
throw new IllegalAccessError(e.getMessage()); } catch (NoSuchFieldException e) { throw new NoSuchFieldError(e.getMessage());
private static Field getField(Class c, String fieldName) { for (Field field : c.getDeclaredFields()) { if (field.getName().equals(fieldName)) { return field; } } throw new NoSuchFieldError("Type '" + c + "' has no field '" + fieldName + "'"); } }
public Field[] getEnumConstants(Class clazz) { try { Object[] values = clazz.getEnumConstants(); Field[] fields = new Field[values.length]; for (int i = 0; i < values.length; i++) { fields[i] = clazz.getField(((Enum) values[i]).name()); } return fields; } catch (NoSuchFieldException e) { // impossible throw new NoSuchFieldError(e.getMessage()); } }
@Override public sun.misc.Unsafe run() throws Exception { Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class; for (java.lang.reflect.Field f : k.getDeclaredFields()) { f.setAccessible(true); Object x = f.get(null); if (k.isInstance(x)) { return k.cast(x); } } throw new NoSuchFieldError("the Unsafe"); } });