@Test public void testEscapingAuthenticator() throws Exception { try { Class<?> k = ErrorAuthenticator.class; jakarta.mail.Authenticator a; a = LogManagerProperties.newObjectFrom(k.getName(), Authenticator.class); assertEquals(k, a.getClass()); setPending(new ThreadDeath()); try { a = LogManagerProperties.newObjectFrom(k.getName(), Authenticator.class); fail(String.valueOf(a)); } catch (ThreadDeath expect) { } setPending(new OutOfMemoryError()); try { a = LogManagerProperties.newObjectFrom(k.getName(), Authenticator.class); fail(String.valueOf(a)); } catch (OutOfMemoryError expect) { } } finally { setPending(null); } }
static <T> T newObjectFrom(String name, Class<T> type) throws Exception { try { final Class<?> clazz = LogManagerProperties.findClass(name); if (type.isAssignableFrom(clazz)) { try { return type.cast(clazz.getConstructor().newInstance()); } catch (final InvocationTargetException ITE) { throw paramOrError(ITE); } } else { throw new ClassCastException(clazz.getName() + " cannot be cast to " + type.getName()); } } catch (final NoClassDefFoundError NCDFE) { throw new ClassNotFoundException(NCDFE.toString(), NCDFE); } catch (final ExceptionInInitializerError EIIE) { throw wrapOrThrow(EIIE); } }
LogManagerProperties extends Properties { static <T> T newObjectFrom(String name, Class<T> type) throws Exception { try { final Class<?> clazz = LogManagerProperties.findClass(name); if (type.isAssignableFrom(clazz)) { try { return type.cast(clazz.getConstructor().newInstance()); } catch (final InvocationTargetException ITE) { throw paramOrError(ITE); } } else { throw new ClassCastException(clazz.getName() + " cannot be cast to " + type.getName()); } } catch (final NoClassDefFoundError NCDFE) { throw new ClassNotFoundException(NCDFE.toString(), NCDFE); } catch (final ExceptionInInitializerError EIIE) { throw wrapOrThrow(EIIE); } } }
LogManagerProperties extends Properties { static <T> T newObjectFrom(String name, Class<T> type) throws Exception { try { final Class<?> clazz = LogManagerProperties.findClass(name); if (type.isAssignableFrom(clazz)) { try { return type.cast(clazz.getConstructor().newInstance()); } catch (final InvocationTargetException ITE) { throw paramOrError(ITE); } } else { throw new ClassCastException(clazz.getName() + " cannot be cast to " + type.getName()); } } catch (final NoClassDefFoundError NCDFE) { throw new ClassNotFoundException(NCDFE.toString(), NCDFE); } catch (final ExceptionInInitializerError EIIE) { throw wrapOrThrow(EIIE); } } LogManagerProperties(final Properties parent, final String prefix); }
LogManagerProperties extends Properties { static <T> T newObjectFrom(String name, Class<T> type) throws Exception { try { final Class<?> clazz = LogManagerProperties.findClass(name); if (type.isAssignableFrom(clazz)) { try { return type.cast(clazz.getConstructor().newInstance()); } catch (final InvocationTargetException ITE) { throw paramOrError(ITE); } } else { throw new ClassCastException(clazz.getName() + " cannot be cast to " + type.getName()); } } catch (final NoClassDefFoundError NCDFE) { throw new ClassNotFoundException(NCDFE.toString(), NCDFE); } catch (final ExceptionInInitializerError EIIE) { throw wrapOrThrow(EIIE); } } LogManagerProperties(final Properties parent, final String prefix); @Override @SuppressWarnings("CloneDoesntCallSuperClone") synchronized Object clone(); @Override synchronized String getProperty(final String key); @Override String getProperty(final String key, final String def); @Override synchronized Object get(final Object key); @Override synchronized Object put(final Object key, final Object value); @Override Object setProperty(String key, String value); @Override synchronized boolean containsKey(final Object key); @Override synchronized Object remove(final Object key); @Override Enumeration<?> propertyNames(); @Override boolean equals(final Object o); @Override int hashCode(); }
LogManagerProperties extends Properties { static <T> T newObjectFrom(String name, Class<T> type) throws Exception { try { final Class<?> clazz = LogManagerProperties.findClass(name); if (type.isAssignableFrom(clazz)) { try { return type.cast(clazz.getConstructor().newInstance()); } catch (final InvocationTargetException ITE) { throw paramOrError(ITE); } } else { throw new ClassCastException(clazz.getName() + " cannot be cast to " + type.getName()); } } catch (final NoClassDefFoundError NCDFE) { throw new ClassNotFoundException(NCDFE.toString(), NCDFE); } catch (final ExceptionInInitializerError EIIE) { throw wrapOrThrow(EIIE); } } LogManagerProperties(final Properties parent, final String prefix); @Override @SuppressWarnings("CloneDoesntCallSuperClone") synchronized Object clone(); @Override synchronized String getProperty(final String key); @Override String getProperty(final String key, final String def); @Override synchronized Object get(final Object key); @Override synchronized Object put(final Object key, final Object value); @Override Object setProperty(String key, String value); @Override synchronized boolean containsKey(final Object key); @Override synchronized Object remove(final Object key); @Override Enumeration<?> propertyNames(); @Override boolean equals(final Object o); @Override int hashCode();  }