History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: XSTR-499
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: Major Major
Assignee: Joerg Schaible
Reporter: Serge Brisson
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
XStream

Rare NPE in Sun14ReflectionProvider

Created: 21/Jun/08 10:47 AM   Updated: 22/Jun/08 10:34 AM
Component/s: Converters
Affects Version/s: 1.3
Fix Version/s: 1.x Maintenance

Issue Links:
Duplicate
 

JDK version and platform: Sun 1.5.0_11 for Windows


 Description  « Hide
In a long running high volume application, we have had an occurence of a NPE at
com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(Sun14ReflectionProvider.java:74).

After looking at the source, at tiny window has been found in the 'getMungedConstructor'
method involving the use of WeakReference and bad luck with the timing of the
garbage collector.

A suggested fix for this method follows:

private Constructor getMungedConstructor(Class type) throws NoSuchMethodException {
WeakReference ref = (WeakReference)constructorCache.get(type);
Constructor mungedConstructor = ref != null? ref.get(): null;
if (mungedConstructor == null) { Constructor javaLangObjectConstructor = Object.class.getDeclaredConstructor(new Class[0]); mungedConstructor = reflectionFactory.newConstructorForSerialization(type, javaLangObjectConstructor); ref = new WeakReference(mungedConstructor); constructorCache.put(type, ref); }
return mungedConstructor;
}

Thank you for your attention.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Joerg Schaible - 22/Jun/08 10:34 AM
Already reported and fixed.