Details
-
Type: Bug
-
Status: Closed
-
Priority: Critical
-
Resolution: Fixed
-
Affects Version/s: 1.3
-
Fix Version/s: 1.3.1
-
Component/s: Converters
-
Labels:None
Description
The JavaBeanConverter does not respect java bean properties that are omitted and don't have a corresponding member variable. This occurs because XStream reads the value of a field before deciding whether to omit it or not.
The following class illustrates the bug:
public class Test { private int safe; public int getSafe() { return safe; } public void setSafe(int s) { safe = s; } public String getUnsafe() { throw new RuntimeException(); } public void setUnsafe(String p) { // Do something } public static void main(String [] args) throws Exception { XStream x = new XStream(); x.omitField(Test.class, "unsafe"); x.omitField(Test.class, "safe"); System.out.println(x.toXML(new Test())); } }
Even though "unsafe" is marked as omitted, XStream still reads the value before deciding to omit it.
I think that xstream should check to see if the field is omitted before reading the value because there are cases where a method may be potentially dangerous or expensive to run.
Patch and test case