]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for 145086
authoraclement <aclement>
Sat, 3 Jun 2006 08:27:06 +0000 (08:27 +0000)
committeraclement <aclement>
Sat, 3 Jun 2006 08:27:06 +0000 (08:27 +0000)
lib/aspectj/lib/aspectjrt.jar
lib/test/aspectjrt.jar
runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java
runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java

index 01aac118057ae5d3cb9afd17687d4b00f4f5230f..80d738327b12671f71aa5ea5672371e0b801d6d8 100644 (file)
Binary files a/lib/aspectj/lib/aspectjrt.jar and b/lib/aspectj/lib/aspectjrt.jar differ
index 01aac118057ae5d3cb9afd17687d4b00f4f5230f..80d738327b12671f71aa5ea5672371e0b801d6d8 100644 (file)
Binary files a/lib/test/aspectjrt.jar and b/lib/test/aspectjrt.jar differ
index 68473c218560a034e4e88ddf26b85996ce28a470..68079b44400c32ca9e4b00d676310be55169c753 100644 (file)
@@ -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;
+               }
+
        }
 }
index 98a5a237457bdd003934c76dd0b283a14493599e..2a17ad998bc47dd681a78f2b737f2a53093ce21d 100644 (file)
@@ -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 {
 
index 6cb43f7e0b04fec022a6a67db15a637d0c2fdb35..7a66a5b3971b30561be47f54b1947e39c0bdfcbd 100644 (file)
@@ -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.         
+       }
 }