@Test(expected = IllegalArgumentException.class) @SuppressWarnings("unchecked") public void testCreationException() throws Exception { TypeCache<Object> typeCache = new TypeCache<Object>(TypeCache.Sort.WEAK); Callable<Class<?>> callable = mock(Callable.class); when(callable.call()).thenThrow(RuntimeException.class); typeCache.findOrInsert(ClassLoader.getSystemClassLoader(), new Object(), callable, new Object()); }
public Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy) { Class<?> type = find(classLoader, key); if (type != null) { return type; } else { try { return insert(classLoader, key, lazy.call()); } catch (Throwable throwable) { throw new IllegalArgumentException("Could not create type", throwable); } } }
TypeCache extends ReferenceQueue<ClassLoader> { public Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy) { Class<?> type = find(classLoader, key); if (type != null) { return type; } else { try { return insert(classLoader, key, lazy.call()); } catch (Throwable throwable) { throw new IllegalArgumentException("Could not create type", throwable); } } } }
TypeCache extends ReferenceQueue<ClassLoader> { public Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy) { Class<?> type = find(classLoader, key); if (type != null) { return type; } else { try { return insert(classLoader, key, lazy.call()); } catch (Throwable throwable) { throw new IllegalArgumentException("Could not create type", throwable); } } } TypeCache(Sort sort); }
TypeCache extends ReferenceQueue<ClassLoader> { public Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy) { Class<?> type = find(classLoader, key); if (type != null) { return type; } else { try { return insert(classLoader, key, lazy.call()); } catch (Throwable throwable) { throw new IllegalArgumentException("Could not create type", throwable); } } } TypeCache(Sort sort); @SuppressFBWarnings(value = "GC_UNRELATED_TYPES", justification = "Cross-comparison is intended") Class<?> find(ClassLoader classLoader, T key); @SuppressFBWarnings(value = "GC_UNRELATED_TYPES", justification = "Cross-comparison is intended") Class<?> insert(ClassLoader classLoader, T key, Class<?> type); Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy); Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy, Object monitor); void expungeStaleEntries(); void clear(); }
TypeCache extends ReferenceQueue<ClassLoader> { public Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy) { Class<?> type = find(classLoader, key); if (type != null) { return type; } else { try { return insert(classLoader, key, lazy.call()); } catch (Throwable throwable) { throw new IllegalArgumentException("Could not create type", throwable); } } } TypeCache(Sort sort); @SuppressFBWarnings(value = "GC_UNRELATED_TYPES", justification = "Cross-comparison is intended") Class<?> find(ClassLoader classLoader, T key); @SuppressFBWarnings(value = "GC_UNRELATED_TYPES", justification = "Cross-comparison is intended") Class<?> insert(ClassLoader classLoader, T key, Class<?> type); Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy); Class<?> findOrInsert(ClassLoader classLoader, T key, Callable<Class<?>> lazy, Object monitor); void expungeStaleEntries(); void clear();  }