XStream

JavaBeanConverter does not respect omitted javabean properties

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical 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.

Activity

Hide
Kevin Conaway added a comment -

Patch and test case

Show
Kevin Conaway added a comment - Patch and test case
Hide
Joerg Schaible added a comment -

Thanks for the patch. Applied in head revision.

Show
Joerg Schaible added a comment - Thanks for the patch. Applied in head revision.
Hide
Joerg Schaible added a comment -

Set correct fix version.

Show
Joerg Schaible added a comment - Set correct fix version.
Hide
Joerg Schaible added a comment -

Fixed for upcoming release.

Show
Joerg Schaible added a comment - Fixed for upcoming release.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: