public boolean isAccessible () { return constructor.isAccessible(); }
public boolean isAccessible () { return constructor.isAccessible(); }
@Override public boolean isAccessible() { return target.isAccessible(); }
@Override public boolean isAccessible() { return target.isAccessible(); }
/** * Make the given constructor accessible, explicitly setting it accessible * if necessary. The {@code setAccessible(true)} method is only called * when actually necessary, to avoid unnecessary conflicts with a JVM * SecurityManager (if active). * @param ctor the constructor to make accessible * @see java.lang.reflect.Constructor#setAccessible */ @SuppressWarnings("deprecation") // on JDK 9 public static void makeAccessible(Constructor<?> ctor) { if ((!Modifier.isPublic(ctor.getModifiers()) || !Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) { ctor.setAccessible(true); } }
public FallbackFastMethod(Constructor<?> constructor) { this.constructor = constructor; if (!this.constructor.isAccessible()) this.constructor.setAccessible(true); }
public AbstractConstructorBorning(Constructor<?> c) { super(); if (!c.isAccessible()) c.setAccessible(true); this.c = c; }
public static <T> T newInstance(Class<T> clazz, ClassLoader classLoader, String className) throws Exception { final Constructor<T> constructor = clazz.getDeclaredConstructor(); if (!constructor.isAccessible()) { constructor.setAccessible(true); } CONSTRUCTOR_CACHE.put(classLoader, className, constructor); return constructor.newInstance(); }
public static <T> T newInstance(Class<T> clazz, ClassLoader classLoader, String className) throws Exception { final Constructor<T> constructor = clazz.getDeclaredConstructor(); if (!constructor.isAccessible()) { constructor.setAccessible(true); } CONSTRUCTOR_CACHE.put(classLoader, className, constructor); return constructor.newInstance(); }
private static MethodHandles.Lookup getConstructorLookup(Class<?> type) throws ReflectiveOperationException { Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class); if (!constructor.isAccessible()) { constructor.setAccessible(true); } return constructor.newInstance(type, ANY_ACCESS); } }
/** * Make the given constructor accessible, explicitly setting it accessible * if necessary. The {@code setAccessible(true)} method is only called * when actually necessary, to avoid unnecessary conflicts with a JVM * SecurityManager (if active). * @param ctor the constructor to make accessible * @see java.lang.reflect.Constructor#setAccessible */ @SuppressWarnings("deprecation") // on JDK 9 public static void makeAccessible(Constructor<?> ctor) { if ((!Modifier.isPublic(ctor.getModifiers()) || !Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) { ctor.setAccessible(true); } }
public static void makeAccessible(Constructor<?> ctor) { if ((!Modifier.isPublic(ctor.getModifiers()) || !Modifier.isPublic(ctor.getDeclaringClass().getModifiers())) && !ctor.isAccessible()) { ctor.setAccessible(true); } }
/** * Checks whether the given class can be used by the {@link ConstructorBasedConverter} (i.e. has a constructor * taking a single String as argument). If so, creates a new instance of converter for this type. * * @param clazz the class * @return a {@link ConstructorBasedConverter} if the given class is eligible, * {@literal null} otherwise. */ public static <T> ConstructorBasedConverter<T> getIfEligible(Class<T> clazz) { try { final Constructor<T> constructor = clazz.getConstructor(String.class); if (!constructor.isAccessible()) { constructor.setAccessible(true); } return new ConstructorBasedConverter<>(constructor); } catch (NoSuchMethodException e) { // The class does not have the right constructor, return null. return null; } }
Object readResolve() { Class<?> clazz = _serialization.clazz; try { Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.args); // 06-Oct-2012, tatu: Has "lost" its security override, must force back if (!ctor.isAccessible()) { ClassUtil.checkAndFixAccess(ctor, false); } return new AnnotatedConstructor(null, ctor, null, null); } catch (Exception e) { throw new IllegalArgumentException("Could not find constructor with " +_serialization.args.length+" args from Class '"+clazz.getName()); } }
Object readResolve() { Class<?> clazz = _serialization.clazz; try { Constructor<?> ctor = clazz.getDeclaredConstructor(_serialization.args); // 06-Oct-2012, tatu: Has "lost" its security override, must force back if (!ctor.isAccessible()) { ClassUtil.checkAndFixAccess(ctor, false); } return new AnnotatedConstructor(null, ctor, null, null); } catch (Exception e) { throw new IllegalArgumentException("Could not find constructor with " +_serialization.args.length+" args from Class '"+clazz.getName()); } }
@SuppressWarnings("deprecation") // on JDK 9 public static Object newInstance(final Constructor cstruct, final Object[] args) { boolean flag = cstruct.isAccessible(); try { if (!flag) { cstruct.setAccessible(true); } Object result = cstruct.newInstance(args); return result; } catch (InstantiationException e) { throw new CodeGenerationException(e); } catch (IllegalAccessException e) { throw new CodeGenerationException(e); } catch (InvocationTargetException e) { throw new CodeGenerationException(e.getTargetException()); } finally { if (!flag) { cstruct.setAccessible(flag); } } }
public static Object newInstance(final Constructor cstruct, final Object[] args) { boolean flag = cstruct.isAccessible(); try { cstruct.setAccessible(true); Object result = cstruct.newInstance(args); return result; } catch (InstantiationException e) { throw new CodeGenerationException(e); } catch (IllegalAccessException e) { throw new CodeGenerationException(e); } catch (InvocationTargetException e) { throw new CodeGenerationException(e.getTargetException()); } finally { cstruct.setAccessible(flag); } }
private Object invokeDefaultMethod(Object proxy, Method method, Object[] args) throws Throwable { final Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class .getDeclaredConstructor(Class.class, int.class); if (!constructor.isAccessible()) { constructor.setAccessible(true); } final Class<?> declaringClass = method.getDeclaringClass(); return constructor .newInstance(declaringClass, MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED | MethodHandles.Lookup.PACKAGE | MethodHandles.Lookup.PUBLIC) .unreflectSpecial(method, declaringClass).bindTo(proxy).invokeWithArguments(args); }
static Constructor<?> newConstructorForSerialization(Class<?> classToInstantiate, Constructor<?> constructorToCall) { final Constructor<?> serCtor = reflectionFactory.newConstructorForSerialization(classToInstantiate, constructorToCall); if (! serCtor.isAccessible()) { // older JDK 8... AccessController.doPrivileged(new SetAccessibleAction(serCtor)); } return serCtor; }
public static void assertHasSinglePrivateConstructor(Class<?> cls) throws Exception { Constructor<?>[] constructors = cls.getDeclaredConstructors(); assertEquals("expected number of constructors to be == 1", 1, constructors.length); Constructor<?> constructor = constructors[0]; assertFalse("expected constructor to be inaccessible", constructor.isAccessible()); constructor.setAccessible(true); constructor.newInstance(); }