jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • XStream
  • XSTR-509

Rare NPE in Sun14ReflectionProvider

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.x Maintenance
  • Fix Version/s: 1.x Maintenance
  • Component/s: Core
  • Labels:
    None
  • JDK version and platform:
    Sun 1.4.2_17 for Windows

Description

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;
}

Issue Links

duplicates

Bug - A problem which impairs or prevents the functions of the product. XSTR-497 getMungedConstructor in Sun14ReflectionProvider is unsafe

  • Major - Major loss of function.
  • Closed - The issue is considered finished, the resolution is correct. Issues which are not closed can be reopened.

Activity

  • All
  • Comments
  • History
  • Activity
There are no comments yet on this issue.

People

  • Assignee:
    Joerg Schaible
    Reporter:
    Frank-Michael Jaeschke
Vote (0)
Watch (0)

Dates

  • Created:
    15/Jul/08 4:58 AM
    Updated:
    15/Jul/08 6:23 AM
    Resolved:
    15/Jul/08 6:23 AM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.