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

Key: XSTR-509
Type: Bug Bug
Status: Closed Closed
Resolution: Duplicate
Priority: Major Major
Assignee: Joerg Schaible
Reporter: Frank-Michael Jaeschke
Votes: 0
Watchers: 0
Operations

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

Rare NPE in Sun14ReflectionProvider

Created: 15/Jul/08 04:58 AM   Updated: 15/Jul/08 06:23 AM
Component/s: Core
Affects Version/s: 1.x Maintenance
Fix Version/s: 1.x Maintenance

Issue Links:
Duplicate
 

JDK version and platform: Sun 1.4.2_17 for Windows


 Description  « Hide
Under unfavorable circumstances method getMungedConstructor in Sun14ReflectionProvider class might return null, what leads to NullPointerException in method newInstance. It occurs when GC has cleared the WeakReference. See stack trace below:

...
Caused by: java.lang.NullPointerException
at com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider.newInstance(Sun14ReflectionProvider.java:74)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:2
79)
at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:149)
at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:81)
... 49 more

This happens as well with current SVN release (rev 1488)

Proposed fix:

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



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.