Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 43360 Details for
Bug 145086
NPE when weak reference set in signature
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Test and fix of NPE on set of weak reference (ugh)
signatureClearingRef.patch.txt (text/plain), 4.28 KB, created by
Ron Bodkin
on 2006-06-02 11:36:29 EDT
(
hide
)
Description:
Test and fix of NPE on set of weak reference (ugh)
Filename:
MIME Type:
Creator:
Ron Bodkin
Created:
2006-06-02 11:36:29 EDT
Size:
4.28 KB
patch
obsolete
>Index: testsrc/org/aspectj/runtime/reflect/SignatureTest.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/runtime/testsrc/org/aspectj/runtime/reflect/SignatureTest.java,v >retrieving revision 1.3 >diff -u -r1.3 SignatureTest.java >--- testsrc/org/aspectj/runtime/reflect/SignatureTest.java 1 Jun 2006 09:43:26 -0000 1.3 >+++ testsrc/org/aspectj/runtime/reflect/SignatureTest.java 2 Jun 2006 15:39:08 -0000 >@@ -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 @@ > 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. >+ } > } >Index: testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/runtime/testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java,v >retrieving revision 1.3 >diff -u -r1.3 JoinPointImplTest.java >--- testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java 1 Jun 2006 09:43:26 -0000 1.3 >+++ testsrc/org/aspectj/runtime/reflect/JoinPointImplTest.java 2 Jun 2006 15:39:08 -0000 >@@ -15,8 +15,6 @@ > /** > * @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: src/org/aspectj/runtime/reflect/SignatureImpl.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java,v >retrieving revision 1.9 >diff -u -r1.9 SignatureImpl.java >--- src/org/aspectj/runtime/reflect/SignatureImpl.java 1 Jun 2006 09:43:25 -0000 1.9 >+++ src/org/aspectj/runtime/reflect/SignatureImpl.java 2 Jun 2006 15:39:08 -0000 >@@ -206,26 +206,38 @@ > } > > // 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; >+ } >+ > } > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
aclement
:
iplog+
Actions:
View
|
Diff
Attachments on
bug 145086
: 43360