XStream
  1. XStream
  2. XSTR-503

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.

        People

        • Assignee:
          Jörg Schaible
          Reporter:
          Kevin Conaway
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: