CachedIntrospectionResults and co consistently avoid synchronization (through use of ConcurrentReferenceHashMap)

As a side effect, through ConcurrentReferenceHashMap, we're using soft references for non-cache-safe bean classes.

Issue: SPR-11867
This commit is contained in:
Juergen Hoeller
2014-06-30 00:16:15 +02:00
parent cb40908a7d
commit fab67b0595
4 changed files with 103 additions and 123 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,35 +33,35 @@ import static org.junit.Assert.*;
* @author Chris Beams
* @author Arjen Poutsma
*/
public final class CachedIntrospectionResultsTests {
public class CachedIntrospectionResultsTests {
@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));
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean");
assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass));
assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
CachedIntrospectionResults.acceptClassLoader(child);
bw = new BeanWrapperImpl(tbClass);
assertTrue(bw.isWritableProperty("name"));
assertTrue(bw.isWritableProperty("age"));
assertTrue(CachedIntrospectionResults.classCache.containsKey(tbClass));
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
CachedIntrospectionResults.clearClassLoader(child);
assertFalse(CachedIntrospectionResults.classCache.containsKey(tbClass));
assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
assertTrue(CachedIntrospectionResults.classCache.containsKey(TestBean.class));
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
}
@Test
public void clearClassLoaderForSystemClassLoader() throws Exception {
BeanUtils.getPropertyDescriptors(ArrayList.class);
assertTrue(CachedIntrospectionResults.classCache.containsKey(ArrayList.class));
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class));
CachedIntrospectionResults.clearClassLoader(ArrayList.class.getClassLoader());
assertFalse(CachedIntrospectionResults.classCache.containsKey(ArrayList.class));
assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class));
}
@Test