XStream
  1. XStream
  2. XSTR-499

Rare NPE in Sun14ReflectionProvider

    Details

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

      Description

      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.

        Issue Links

          People

          • Assignee:
            Jörg Schaible
            Reporter:
            Serge Brisson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: