Incorrect deserialization of null values in Map
-----------------------------------------------
Key: CXF-1947
URL: https://issues.apache.org/jira/browse/CXF-1947
Project: CXF
Issue Type: Bug
Components: Aegis Databinding
Reporter: Julien Coloos
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
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.