public RuntimeTestWalker(ShadowMatch shadowMatch) { try { ReflectionUtils.makeAccessible(residualTestField); this.runtimeTest = (Test) residualTestField.get(shadowMatch); } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } }
@Override @Nullable public Object getValue() throws Exception { try { ReflectionUtils.makeAccessible(this.field); return this.field.get(getWrappedInstance()); } catch (IllegalAccessException ex) { throw new InvalidPropertyException(getWrappedClass(), this.field.getName(), "Field is not accessible", ex); } }
protected int getVarType(ReflectionVar v) { try { ReflectionUtils.makeAccessible(varTypeField); return (Integer) varTypeField.get(v); } catch (IllegalAccessException ex) { throw new IllegalStateException(ex); } } }
static void assertConstantNameMatchesString( Class<?> clazz, ImmutableBiMap<String, String> specialCases, ImmutableSet<String> uppercaseAcronyms) throws IllegalAccessException { for (Field field : relevantFields(clazz)) { assertEquals( upperToHttpHeaderName(field.getName(), specialCases, uppercaseAcronyms), field.get(null)); } }
@Override void serialize(AbstractHessianOutput out, Object obj, Field field) throws IOException { String value = null; try { value = (String) field.get(obj); } catch (IllegalAccessException e) { log.log(Level.FINE, e.toString(), e); } out.writeString(value); } }
@GwtIncompatible // reflection public void testConstants_charset() throws Exception { for (Field field : getConstantFields()) { Optional<Charset> charset = ((MediaType) field.get(null)).charset(); if (field.getName().endsWith("_UTF_8")) { assertThat(charset).hasValue(UTF_8); } else { assertThat(charset).isAbsent(); } } }
@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 ClassLoader getThrowawayClassLoader() { try { ClassLoader loader = this.cloneConstructor.newInstance(getClassLoader()); // Clear out the transformers (copied as well) List<?> list = (List<?>) this.transformerList.get(loader); list.clear(); return loader; } catch (InvocationTargetException ex) { throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause()); } catch (Throwable ex) { throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex); } }
@Override public MediaType apply(Field input) { try { return (MediaType) input.get(null); } catch (Exception e) { throw new RuntimeException(e); } } });
private static Map<?, ?> getSerializableFactoryMap() throws Exception { Field field = DefaultListableBeanFactory.class.getDeclaredField("serializableFactories"); field.setAccessible(true); return (Map<?, ?>) field.get(DefaultListableBeanFactory.class); }
@SuppressWarnings("unchecked") public Map<String, String> getMap(Object target) { try { Field f = target.getClass().getDeclaredField(mapName); return (Map<String, String>) f.get(target); } catch (Exception ex) { } return null; }
@SuppressWarnings("unchecked") private static Map<ClassLoader, WebApplicationContext> getCurrentContextPerThreadFromContextLoader() { try { Field field = ContextLoader.class.getDeclaredField("currentContextPerThread"); field.setAccessible(true); return (Map<ClassLoader, WebApplicationContext>) field.get(null); } catch (Exception ex) { throw new IllegalStateException(ex); } }
@GwtIncompatible // reflection private static int bucketsOf(HashMap<?, ?> hashMap) throws Exception { Field tableField = HashMap.class.getDeclaredField("table"); tableField.setAccessible(true); Object[] table = (Object[]) tableField.get(hashMap); // In JDK8, table is set lazily, so it may be null. return table == null ? 0 : table.length; }
private void checkHelperVersion(ClassLoader classLoader, String expectedHelperClassName) throws Exception { // Make sure we are actually running with the expected helper implementation Class<?> abstractFutureClass = classLoader.loadClass(AbstractFuture.class.getName()); Field helperField = abstractFutureClass.getDeclaredField("ATOMIC_HELPER"); helperField.setAccessible(true); assertEquals(expectedHelperClassName, helperField.get(null).getClass().getSimpleName()); }
private void checkHelperVersion(ClassLoader classLoader, String expectedHelperClassName) throws Exception { // Make sure we are actually running with the expected helper implementation Class<?> abstractFutureClass = classLoader.loadClass(AggregateFutureState.class.getName()); Field helperField = abstractFutureClass.getDeclaredField("ATOMIC_HELPER"); helperField.setAccessible(true); assertEquals(expectedHelperClassName, helperField.get(null).getClass().getSimpleName()); }
private void assertIsCompiled(Expression expression) { try { Field field = SpelExpression.class.getDeclaredField("compiledAst"); field.setAccessible(true); Object object = field.get(expression); assertNotNull(object); } catch (Exception ex) { fail(ex.toString()); } }
@Test public void defaultRefreshCheckDelay() throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG); Advised advised = (Advised) context.getBean("testBean"); AbstractRefreshableTargetSource targetSource = ((AbstractRefreshableTargetSource) advised.getTargetSource()); Field field = AbstractRefreshableTargetSource.class.getDeclaredField("refreshCheckDelay"); field.setAccessible(true); long delay = ((Long) field.get(targetSource)).longValue(); assertEquals(5000L, delay); }
@Test public void isDefaultJndiEnvironmentAvailableFalse() throws Exception { Field builderField = NamingManager.class.getDeclaredField("initctx_factory_builder"); builderField.setAccessible(true); Object oldBuilder = builderField.get(null); builderField.set(null, null); try { assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable(), equalTo(false)); } finally { builderField.set(null, oldBuilder); } }
/** Returns the value of the field on the supplied object. */ public Object get (Object obj) throws ReflectionException { try { return field.get(obj); } catch (IllegalArgumentException e) { throw new ReflectionException("Object is not an instance of " + getDeclaringClass(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to field: " + getName(), e); } }
/** Returns the value of the field on the supplied object. */ public Object get (Object obj) throws ReflectionException { try { return field.get(obj); } catch (IllegalArgumentException e) { throw new ReflectionException("Object is not an instance of " + getDeclaringClass(), e); } catch (IllegalAccessException e) { throw new ReflectionException("Illegal access to field: " + getName(), e); } }