FieldReflector(ObjectStreamField[] fields){
  this.fields=fields;
  int nfields=fields.length;
  readKeys=new long[nfields];
  writeKeys=new long[nfields];
  offsets=new int[nfields];
  typeCodes=new char[nfields];
  ArrayList<Class<?>> typeList=new ArrayList<>();
  Set<Long> usedKeys=new HashSet<>();
  for (int i=0; i < nfields; i++) {
    ObjectStreamField f=fields[i];
    Field rf=f.getField();
    long key=(rf != null) ? unsafe.objectFieldOffset(rf) : Unsafe.INVALID_FIELD_OFFSET;
    readKeys[i]=key;
    writeKeys[i]=usedKeys.add(key) ? key : Unsafe.INVALID_FIELD_OFFSET;
    offsets[i]=f.getOffset();
    typeCodes[i]=f.getTypeCode();
    if (!f.isPrimitive()) {
      typeList.add((rf != null) ? rf.getType() : null);
    }
  }
  types=typeList.toArray(new Class<?>[typeList.size()]);
  numPrimFields=nfields - types.length;
}

FieldReflector ( ObjectStreamField [ ] fields ) { this . fields = fields ; int nfields = fields . length ; readKeys = new long [ nfields ] ; writeKeys = new long [ nfields ] ; offsets = new int [ nfields ] ; typeCodes = new char [ nfields ] ; ArrayList < Class < ? > > typeList = new ArrayList < > ( ) ; Set < Long > usedKeys = new HashSet < > ( ) ; for ( int i = 0 ; i < nfields ; i ++ ) { ObjectStreamField f = fields [ i ] ; Field rf = f . getField ( ) ; long key = ( rf != null ) ? unsafe . objectFieldOffset ( rf ) : Unsafe . INVALID_FIELD_OFFSET ; readKeys [ i ] = key ; writeKeys [ i ] = usedKeys . add ( key ) ? key : Unsafe . INVALID_FIELD_OFFSET ; offsets [ i ] = f . getOffset ( ) ; typeCodes [ i ] = f . getTypeCode ( ) ; if ( ! f . isPrimitive ( ) ) { typeList . add ( ( rf != null ) ? rf . getType ( ) : null ) ; } } types = typeList . toArray ( new Class < ? > [ typeList . size ( ) ] ) ; numPrimFields = nfields - types . length ; }
constructs fieldreflector capable of setting / getting values from the subset of fields whose objectstreamfields contain non - null reflective field objects . objectstreamfields with null fields are treated as filler , for which get operations return default values and set operations discard given values .
