Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-1947

Incorrect deserialization of null values in Map

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0, 2.0.1, 2.0.2, 2.0.3, 2.0.4, 2.0.5, 2.1, 2.0.6, 2.1.1, 2.0.7, 2.0.8, 2.1.2, 2.0.9, 2.1.3
    • 2.0.10, 2.1.4
    • Aegis Databinding
    • None
    • Unknown

    Description

      Hi,

      There is an issue with AEGIS deserialization (at least on server-side) of Maps that contain null values: the retrieved value may not be null, and can actually be the previous value deserialized from the Map.
      For exemple, if the Map contains 3 (key;value) pairs ("0", null), ("1", Object1) and ("2", null), AEGIS will hand over ("0", null), ("1", Object1) and ("2", Object1) to the implementation class.

      I had a quick look at the source code, and I think the issue is in the org.apache.cxf.aegis.type.collection.MapType.readObject(MessageReader, Context) function: the variables holding the key and value objects are declared outside the loop processing the Map elements (named 'entry' in the XML stream), and are not reseted to null for each 'entry' processed.
      So if the 'key' or 'value' tag is absent (meaning the data is null), the code still points to the deserialized data from the previous entry.

      This could be fixed by either moving the declaration of those 2 variables inside the loop, or reseting their values to null at the beginning of the loop.

      Snippet from the function :

      Object key = null;
      Object value = null;

      while (reader.hasMoreElementReaders()) {
      MessageReader entryReader = reader.getNextElementReader();

      if (entryReader.getName().equals(getEntryName())) {
      while (entryReader.hasMoreElementReaders()) {
      MessageReader evReader = entryReader.getNextElementReader();

      if (evReader.getName().equals(getKeyName()))

      { key = kType.readObject(evReader, context); }

      else if (evReader.getName().equals(getValueName()))

      { value = vType.readObject(evReader, context); }

      else

      { readToEnd(evReader); }

      }

      map.put(key, value);
      } else

      { readToEnd(entryReader); }

      }

      Note: this issue was already present in XFire

      Attachments

        Activity

          People

            bmargulies Benson Margulies
            cyrius Julien Coloos
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: