private static Class<?> getCommandClass(String request) { Class<?> result; try { result = Class.forName("com.iluwatar.front.controller." + request + "Command"); } catch (ClassNotFoundException e) { result = UnknownCommand.class; } return result; } }
private Object readResolve() { try { Class c = Class.forName("java.time.OffsetDateTime"); Method m = c.getDeclaredMethod("of", Class.forName("java.time.LocalDateTime"), Class.forName("java.time.ZoneOffset")); return m.invoke(null, dateTime, offset); } catch (Throwable t) { // ignore } return null; } }
@Override public Class<?> loadFinalizer() { try { return Class.forName(FINALIZER_CLASS_NAME); } catch (ClassNotFoundException e) { throw new AssertionError(e); } } }
private static boolean isPresent(String className) { try { Class.forName(className, false, LogAdapter.class.getClassLoader()); return true; } catch (ClassNotFoundException ex) { return false; } }
private Object readResolve() { try { Class c = Class.forName("java.time.Instant"); Method m = c.getDeclaredMethod("ofEpochSecond", long.class, long.class); return m.invoke(null, seconds, nanos); } catch (Throwable t) { // ignore } return null; } }
private Object readResolve() { try { Class c = Class.forName("java.time.Period"); Method m = c.getDeclaredMethod("of", int.class, int.class, int.class); return m.invoke(null, years, months, days); } catch (Throwable t) { // ignore } return null; } }
public YearHandle(Object o) { try { Class c = Class.forName("java.time.Year"); Method m = c.getDeclaredMethod("getValue"); this.year = (Integer) m.invoke(o); } catch (Throwable t) { // ignore } }
private Object readResolve() { try { Class c = Class.forName("java.time.Year"); Method m = c.getDeclaredMethod("of", int.class); return m.invoke(null, year); } catch (Throwable t) { // ignore } return null; } }
public InstantHandle(Object o) { try { Class c = Class.forName("java.time.Instant"); Method m = c.getDeclaredMethod("getEpochSecond"); this.seconds = (Long) m.invoke(o); m = c.getDeclaredMethod("getNano"); this.nanos = (Integer) m.invoke(o); } catch (Throwable t) { // ignore } }
public DurationHandle(Object o) { try { Class c = Class.forName("java.time.Duration"); Method m = c.getDeclaredMethod("getSeconds"); this.seconds = (Long) m.invoke(o); m = c.getDeclaredMethod("getNano"); this.nanos = (Integer) m.invoke(o); } catch (Throwable t) { // ignore } }
public CertificateChainCleaner buildCertificateChainCleaner(X509TrustManager trustManager) { try { Class<?> extensionsClass = Class.forName("android.net.http.X509TrustManagerExtensions"); Constructor<?> constructor = extensionsClass.getConstructor(X509TrustManager.class); Object extensions = constructor.newInstance(trustManager); Method checkServerTrusted = extensionsClass.getMethod( "checkServerTrusted", X509Certificate[].class, String.class, String.class); return new AndroidCertificateChainCleaner(extensions, checkServerTrusted); } catch (Exception e) { throw new AssertionError(e); } }
static ClassName checkResult() { try { Class.forName(ANDROIDX_CHECK_RESULT_ANNOTATION.reflectionName()); return ANDROIDX_CHECK_RESULT_ANNOTATION; } catch (ClassNotFoundException e) { return CHECK_RESULT_ANNOTATION; } }
static ClassName nonNull() { try { Class.forName(ANDROIDX_NONNULL_ANNOTATION.reflectionName()); return ANDROIDX_NONNULL_ANNOTATION; } catch (ClassNotFoundException e) { return NONNULL_ANNOTATION; } }
private static boolean isZoneId(Class cl) { try { return isJava8() && Class.forName("java.time.ZoneId").isAssignableFrom(cl); } catch (ClassNotFoundException e) { // ignore } return false; }
@Override public boolean isCleartextTrafficPermitted(String hostname) { try { Class<?> networkPolicyClass = Class.forName("android.security.NetworkSecurityPolicy"); Method getInstanceMethod = networkPolicyClass.getMethod("getInstance"); Object networkSecurityPolicy = getInstanceMethod.invoke(null); return api24IsCleartextTrafficPermitted(hostname, networkPolicyClass, networkSecurityPolicy); } catch (ClassNotFoundException | NoSuchMethodException e) { return super.isCleartextTrafficPermitted(hostname); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { throw new AssertionError("unable to determine cleartext support", e); } }
private static Method getJdkNextDown() throws Exception { try { return Math.class.getMethod("nextDown", double.class); } catch (NoSuchMethodException expectedBeforeJava8) { return Class.forName("sun.misc.FpUtils").getMethod("nextDown", double.class); } }
public static ConscryptPlatform buildIfSupported() { try { // Trigger an early exception over a fatal error, prefer a RuntimeException over Error. Class.forName("org.conscrypt.Conscrypt"); if (!Conscrypt.isAvailable()) { return null; } return new ConscryptPlatform(); } catch (ClassNotFoundException e) { return null; } }
@Bean @Lazy public Object notLoadable() throws Exception { return Class.forName("does.not.exist").newInstance(); } }
@Test public void testCollectionsEmptyList() throws Exception { CollectionToCollectionConverter converter = new CollectionToCollectionConverter(new GenericConversionService()); TypeDescriptor type = new TypeDescriptor(getClass().getField("list")); converter.convert(list, type, TypeDescriptor.valueOf(Class.forName("java.util.Collections$EmptyList"))); }
public void testLexicographicalComparatorChoice() throws Exception { Comparator<byte[]> defaultComparator = UnsignedBytes.lexicographicalComparator(); assertNotNull(defaultComparator); assertSame(defaultComparator, UnsignedBytes.lexicographicalComparator()); if (unsafeComparatorAvailable()) { assertSame(defaultComparator.getClass(), Class.forName(unsafeComparatorClassName())); } else { assertSame(defaultComparator, UnsignedBytes.lexicographicalComparatorJavaImpl()); } }