@Test public void acceptAndClearClassLoader() throws Exception { BeanWrapper bw = new BeanWrapperImpl(TestBean.class); assertTrue(bw.isWritableProperty("name")); assertTrue(bw.isWritableProperty("age")); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class)); ClassLoader child = new OverridingClassLoader(getClass().getClassLoader()); Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean"); assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)); CachedIntrospectionResults.acceptClassLoader(child); bw = new BeanWrapperImpl(tbClass); assertTrue(bw.isWritableProperty("name")); assertTrue(bw.isWritableProperty("age")); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)); CachedIntrospectionResults.clearClassLoader(child); assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)); assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class)); }
@Test public void acceptAndClearClassLoader() throws Exception { BeanWrapper bw = new BeanWrapperImpl(TestBean.class); assertTrue(bw.isWritableProperty("name")); assertTrue(bw.isWritableProperty("age")); assertTrue(CachedIntrospectionResults.classCache.containsKey(TestBean.class)); ClassLoader child = new OverridingClassLoader(getClass().getClassLoader()); Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean"); assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass)); CachedIntrospectionResults.acceptClassLoader(child); bw = new BeanWrapperImpl(tbClass); assertTrue(bw.isWritableProperty("name")); assertTrue(bw.isWritableProperty("age")); assertTrue(CachedIntrospectionResults.classCache.containsKey(tbClass)); CachedIntrospectionResults.clearClassLoader(child); assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass)); assertTrue(CachedIntrospectionResults.classCache.containsKey(TestBean.class)); }
@Override public ClassLoader getThrowawayClassLoader() { if (this.getThrowawayClassLoaderMethod != null) { ClassLoader target = (ClassLoader) ReflectionUtils.invokeMethod(this.getThrowawayClassLoaderMethod, this.classLoader); return (target instanceof DecoratingClassLoader ? target : new OverridingClassLoader(this.classLoader, target)); } else { return new SimpleThrowawayClassLoader(this.classLoader); } }
@Override public ClassLoader getThrowawayClassLoader() { return new OverridingClassLoader(this.classLoader.getClassLoader(), this.classLoader.getThrowawayClassLoader()); }