/** * Try to call {@link AccessibleObject#setAccessible(boolean)} but will catch any {@link SecurityException} and * {@link java.lang.reflect.InaccessibleObjectException} and return it. * The caller must check if it returns {@code null} and if not handle the returned exception. */ public static Throwable trySetAccessible(AccessibleObject object, boolean checkAccessible) { if (checkAccessible && !PlatformDependent0.isExplicitTryReflectionSetAccessible()) { return new UnsupportedOperationException("Reflective setAccessible(true) disabled"); } try { object.setAccessible(true); return null; } catch (SecurityException e) { return e; } catch (RuntimeException e) { return handleInaccessibleObjectException(e); } }
@Override public Object run() { try { Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys"); Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys"); Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true); if (cause != null) { return cause; } cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true); if (cause != null) { return cause; } selectedKeysField.set(unwrappedSelector, selectedKeySet); publicSelectedKeysField.set(unwrappedSelector, selectedKeySet); return null; } catch (NoSuchFieldException e) { return e; } catch (IllegalAccessException e) { return e; } } });
/** * Try to call {@link AccessibleObject#setAccessible(boolean)} but will catch any {@link SecurityException} and * {@link java.lang.reflect.InaccessibleObjectException} and return it. * The caller must check if it returns {@code null} and if not handle the returned exception. */ public static Throwable trySetAccessible(AccessibleObject object, boolean checkAccessible) { if (checkAccessible && !PlatformDependent0.isExplicitTryReflectionSetAccessible()) { return new UnsupportedOperationException("Reflective setAccessible(true) disabled"); } try { object.setAccessible(true); return null; } catch (SecurityException e) { return e; } catch (RuntimeException e) { return handleInaccessibleObjectException(e); } }
Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true); if (cause != null) { return cause; cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true); if (cause != null) { return cause;
/** * Try to call {@link AccessibleObject#setAccessible(boolean)} but will catch any {@link SecurityException} and * {@link java.lang.reflect.InaccessibleObjectException} and return it. * The caller must check if it returns {@code null} and if not handle the returned exception. */ public static Throwable trySetAccessible(AccessibleObject object, boolean checkAccessible) { if (checkAccessible && !PlatformDependent0.isExplicitTryReflectionSetAccessible()) { return new UnsupportedOperationException("Reflective setAccessible(true) disabled"); } try { object.setAccessible(true); return null; } catch (SecurityException e) { return e; } catch (RuntimeException e) { return handleInaccessibleObjectException(e); } }
Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true); if (cause != null) { return cause; cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true); if (cause != null) { return cause;
/** * Try to call {@link AccessibleObject#setAccessible(boolean)} but will catch any {@link SecurityException} and * {@link java.lang.reflect.InaccessibleObjectException} and return it. * The caller must check if it returns {@code null} and if not handle the returned exception. */ public static Throwable trySetAccessible(AccessibleObject object, boolean checkAccessible) { if (checkAccessible && !PlatformDependent0.isExplicitTryReflectionSetAccessible()) { return new UnsupportedOperationException("Reflective setAccessible(true) disabled"); } try { object.setAccessible(true); return null; } catch (SecurityException e) { return e; } catch (RuntimeException e) { return handleInaccessibleObjectException(e); } }
@Override public Object run() { try { Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys"); Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys"); Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true); if (cause != null) { return cause; } cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true); if (cause != null) { return cause; } selectedKeysField.set(unwrappedSelector, selectedKeySet); publicSelectedKeysField.set(unwrappedSelector, selectedKeySet); return null; } catch (NoSuchFieldException e) { return e; } catch (IllegalAccessException e) { return e; } } });
/** * Try to call {@link AccessibleObject#setAccessible(boolean)} but will catch any {@link SecurityException} and * {@link java.lang.reflect.InaccessibleObjectException} and return it. * The caller must check if it returns {@code null} and if not handle the returned exception. */ public static Throwable trySetAccessible(AccessibleObject object, boolean checkAccessible) { if (checkAccessible && !PlatformDependent0.isExplicitTryReflectionSetAccessible()) { return new UnsupportedOperationException("Reflective setAccessible(true) disabled"); } try { object.setAccessible(true); return null; } catch (SecurityException e) { return e; } catch (RuntimeException e) { return handleInaccessibleObjectException(e); } }
@Override public Object run() { try { Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys"); Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys"); Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true); if (cause != null) { return cause; } cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true); if (cause != null) { return cause; } selectedKeysField.set(unwrappedSelector, selectedKeySet); publicSelectedKeysField.set(unwrappedSelector, selectedKeySet); return null; } catch (NoSuchFieldException e) { return e; } catch (IllegalAccessException e) { return e; } } });
/** * Try to call {@link AccessibleObject#setAccessible(boolean)} but will catch any {@link SecurityException} and * {@link java.lang.reflect.InaccessibleObjectException} and return it. * The caller must check if it returns {@code null} and if not handle the returned exception. */ public static Throwable trySetAccessible(AccessibleObject object, boolean checkAccessible) { if (checkAccessible && !PlatformDependent0.isExplicitTryReflectionSetAccessible()) { return new UnsupportedOperationException("Reflective setAccessible(true) disabled"); } try { object.setAccessible(true); return null; } catch (SecurityException e) { return e; } catch (RuntimeException e) { return handleInaccessibleObjectException(e); } }
@Override public Object run() { try { Field selectedKeysField = selectorImplClass.getDeclaredField("selectedKeys"); Field publicSelectedKeysField = selectorImplClass.getDeclaredField("publicSelectedKeys"); Throwable cause = ReflectionUtil.trySetAccessible(selectedKeysField, true); if (cause != null) { return cause; } cause = ReflectionUtil.trySetAccessible(publicSelectedKeysField, true); if (cause != null) { return cause; } selectedKeysField.set(unwrappedSelector, selectedKeySet); publicSelectedKeysField.set(unwrappedSelector, selectedKeySet); return null; } catch (NoSuchFieldException e) { return e; } catch (IllegalAccessException e) { return e; } } });
/** * Try to call {@link AccessibleObject#setAccessible(boolean)} but will catch any {@link SecurityException} and * {@link java.lang.reflect.InaccessibleObjectException} and return it. * The caller must check if it returns {@code null} and if not handle the returned exception. */ public static Throwable trySetAccessible(AccessibleObject object, boolean checkAccessible) { if (checkAccessible && !PlatformDependent0.isExplicitTryReflectionSetAccessible()) { return new UnsupportedOperationException("Reflective setAccessible(true) disabled"); } try { object.setAccessible(true); return null; } catch (SecurityException e) { return e; } catch (RuntimeException e) { return handleInaccessibleObjectException(e); } }