aboutsummaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authoraclement <aclement>2006-06-03 08:27:06 +0000
committeraclement <aclement>2006-06-03 08:27:06 +0000
commitf821ca3dae5681758d23a2a0531d0d42f017152e (patch)
tree3491c922fb391517009f0ffec94535bbbdaa9a77 /runtime
parent73d96a5cf3bb38a2fbda7f8ae00a7725c9728ec6 (diff)
downloadaspectj-f821ca3dae5681758d23a2a0531d0d42f017152e.tar.gz
aspectj-f821ca3dae5681758d23a2a0531d0d42f017152e.zip
test and fix for 145086
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java36
-rw-r--r--runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java2
-rw-r--r--runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java23
3 files changed, 47 insertions, 14 deletions
diff --git a/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
index 68473c218..68079b444 100644
--- a/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
+++ b/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
@@ -206,26 +206,38 @@ abstract class SignatureImpl implements Signature {
}
// separate implementation so we don't need SoftReference to hold the field...
- private static final class CacheImpl implements Cache {
+ private static final class CacheImpl implements Cache {
private java.lang.ref.SoftReference toStringCacheRef;
- public CacheImpl() {
- toStringCacheRef = new java.lang.ref.SoftReference(new String[3]);
+
+ public CacheImpl() {
+ makeCache();
}
-
+
public String get(int cacheOffset) {
- String[] cachedArray = array();
- if (cachedArray == null) {
- return null;
- }
- return cachedArray[cacheOffset];
+ String[] cachedArray = array();
+ if (cachedArray == null) {
+ return null;
+ }
+ return cachedArray[cacheOffset];
}
public void set(int cacheOffset, String result) {
- array()[cacheOffset] = result;
+ String[] cachedArray = array();
+ if (cachedArray == null) {
+ cachedArray = makeCache();
+ }
+ cachedArray[cacheOffset] = result;
}
-
+
private String[] array() {
- return (String[])toStringCacheRef.get();
+ return (String[]) toStringCacheRef.get();
}
+
+ private String[] makeCache() {
+ String[] array = new String[3];
+ toStringCacheRef = new java.lang.ref.SoftReference(array);
+ return array;
+ }
+
}
}
diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java
index 98a5a2374..2a17ad998 100644
--- a/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java
+++ b/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java
@@ -15,8 +15,6 @@ import junit.framework.TestCase;
/**
* @author colyer
*
- * TODO To change the template for this generated type comment go to
- * Window - Preferences - Java - Code Style - Code Templates
*/
public class JoinPointImplTest extends TestCase {
diff --git a/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java b/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java
index 6cb43f7e0..7a66a5b39 100644
--- a/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java
+++ b/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.aspectj.runtime.reflect;
+import java.lang.ref.Reference;
+import java.lang.reflect.Field;
+
import junit.framework.TestCase;
/**
@@ -31,4 +34,24 @@ public class SignatureTest extends TestCase {
assertSame(longString,msi.toLongString()); // should be cached.
assertTrue("String representations should be different",!(shortString.equals(middleString) || middleString.equals(longString) || longString.equals(shortString)));
}
+
+ public void testClearCache() throws Exception {
+ MethodSignatureImpl msi = new MethodSignatureImpl(0,"test",SignatureTest.class,new Class[] { String.class, Integer.TYPE }, new String[] { "s", "i" }, new Class[] {}, Runnable.class);
+ String shortString = msi.toShortString();
+ assertSame(shortString,msi.toShortString());
+
+ Field field = SignatureImpl.class.getDeclaredField("stringCache");
+ field.setAccessible(true);
+ Object res = field.get(msi);
+
+ field = res.getClass().getDeclaredField("toStringCacheRef");
+ field.setAccessible(true);
+ Reference ref = (Reference)field.get(res);
+
+ ref.clear();
+ assertEquals(shortString,msi.toShortString());
+
+ String longString = msi.toLongString();
+ assertSame(longString,msi.toLongString()); // should be cached.
+ }
}