             //log.debug("Reading object...");
             readBareObjectImpl(target, cmap.streamer);
             if (DEBUG) log.debug(DEBUG_ID + "Read object: " + target);
+            if (type != null && !(target is type)) {
+                log.warning("Type mismatch", "expected", type, "read", ClassUtil.getClass(target));
+                return null;
+            }
             return target;
 
         } catch (me :MemoryError) {

        _source = source;
    }

    public function readObject () :Object
        //throws IOError
    {
        var DEBUG_ID :String = "[" + (++_debugObjectCounter) + "] ";

import com.threerings.util.ClassUtil;
import com.threerings.util.Log;
import com.threerings.util.Long;
import com.threerings.util.safeCast;

public class ObjectInputStream
{
