Issue Details (XML | Word | Printable)

Key: XSTR-503
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Joerg Schaible
Reporter: Kevin Conaway
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
XStream

JavaBeanConverter does not respect omitted javabean properties

Created: 27/Jun/08 03:27 PM   Updated: 01/Dec/08 04:16 PM
Component/s: Converters
Affects Version/s: 1.3
Fix Version/s: 1.3.1

File Attachments: 1. Text File xstr-503.patch (4 kB)



 Description  « Hide
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.



 All   Comments   Change History      Sort Order: Ascending order - Click to sort in descending order
Kevin Conaway added a comment - 27/Jun/08 03:28 PM
Patch and test case

Joerg Schaible added a comment - 22/Sep/08 04:26 AM
Thanks for the patch. Applied in head revision.

Joerg Schaible added a comment - 01/Dec/08 04:15 PM
Set correct fix version.

Joerg Schaible added a comment - 01/Dec/08 04:16 PM
Fixed for upcoming release.