#518 Problem in check of reflective field set

qualidafial Fri 10 Apr 2009

  • Run examples\fan\demo.fan
  • Go to "Text" tab, click "Serialize Demo"
  • Set focus in right-hand text box, select all and copy to clipboard.
  • Go to "Serialization" tab
  • Replace text in left-hand text box with contents of clipboard.
  • Click "=>"
  • Error message is shown:
    sys::IOErr: Cannot set field fwt::Combo.items: sys::ArgErr: Wrong type for field fwt::Combo.items: sys::Obj[] != sys::Str[] [Line 313]
      fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:280)
      fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:224)
      fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
      fanx.serial.ObjDecoder.readComplexAdd (ObjDecoder.java:248)
      fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:236)
      fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
      fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:268)
      fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:224)
      fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
      fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:268)
      fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:224)
      fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
      fanx.serial.ObjDecoder.readComplexAdd (ObjDecoder.java:248)
      fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:236)
      fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
      fanx.serial.ObjDecoder.readComplexAdd (ObjDecoder.java:248)
      fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:236)
      fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
      fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:268)
      fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:224)
      fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
      More...
    Cause:
      sys::ArgErr: Wrong type for field fwt::Combo.items: sys::Obj[] != sys::Str[]
        fan.sys.Field.set (Field.java:103)
        fan.sys.Field.set (Field.java:79)
        fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:276)
        fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:224)
        fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
        fanx.serial.ObjDecoder.readComplexAdd (ObjDecoder.java:248)
        fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:236)
        fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
        fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:268)
        fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:224)
        fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
        fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:268)
        fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:224)
        fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
        fanx.serial.ObjDecoder.readComplexAdd (ObjDecoder.java:248)
        fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:236)
        fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
        fanx.serial.ObjDecoder.readComplexAdd (ObjDecoder.java:248)
        fanx.serial.ObjDecoder.readComplex (ObjDecoder.java:236)
        fanx.serial.ObjDecoder.readObj (ObjDecoder.java:143)
        fanx.serial.ObjDecoder.readComplexField (ObjDecoder.java:268)
        More...

brian Sat 11 Apr 2009

I guess I am not surprised that something as complex as the entire demo doesn't serialize correct - I've never tried that. But I will take a look when I get a chance. Thanks.

qualidafial Tue 14 Apr 2009

I think this is a bug in Field.java:

// check generic type (the Java runtime will check non-generics)
if (of.isGenericInstance() && value != null)
{
  if (!of.is(type(value)))
    throw ArgErr.make("Wrong type for field " + qname() + ": " + of + " != " + type(value)).val;
}

The code is checking whether the destination field's type fits the new value's type, but it should be checking the other way around.

// check generic type (the Java runtime will check non-generics)
if (of.isGenericInstance() && value != null)
{
  if (!type(value).is(of))
    throw ArgErr.make("Wrong type for field " + qname() + ": " + of + " != " + type(value)).val;
}

The C# sources need to be fixed likewise.

brian Wed 15 Apr 2009

Promoted to ticket #518 and assigned to brian

brian Wed 15 Apr 2009

Renamed from Problem in examples\fan\demo.fan to Problem in check of reflective field set

brian Wed 15 Apr 2009

Thanks for tracking that problem down. Seems we were missing a test for that case. I pushed the fix and added a test.

Ticket resolved in 1.0.42

qualidafial Wed 15 Apr 2009

Verified against tip, thanks for the fix.

Login or Signup to reply.