code: int readReferenceOrNull (Input input, Class type, boolean mayBeNull) {
  		if (type.isPrimitive()) type = getWrapperClass(type);
  		boolean referencesSupported = referenceResolver.useReferences(type);
  		int id;
  		if (mayBeNull) {
  			id = input.readVarInt(true);
  			if (id == NULL) {
  				if (TRACE || (DEBUG && depth == 1)) log("Read", null, input.position());
  				readObject = null;
  				return REF;
  			}
  			if (!referencesSupported) {
  				readReferenceIds.add(NO_REF);
  				return readReferenceIds.size;
  			}
  		} else {
  			if (!referencesSupported) {
  				readReferenceIds.add(NO_REF);
  				return readReferenceIds.size;
  			}
  			id = input.readVarInt(true);
  		}
  		if (id == NOT_NULL) {
  			if (TRACE) trace("kryo", "Read: <not null>" + pos(input.position()));
  			// First time object has been encountered.
  			id = referenceResolver.nextReadId(type);
  			if (TRACE) trace("kryo", "Read initial reference " + id + ": " + className(type) + pos(input.position()));
  			readReferenceIds.add(id);
  			return readReferenceIds.size;
  		}
  		// The id is an object reference.
  		id -= 2; // - 2 because 0 and 1 are used for NULL and NOT_NULL.
  		readObject = referenceResolver.getReadObject(type, id);
  		if (DEBUG) debug("kryo", "Read reference " + id + ": " + string(readObject) + pos(input.position()));
  		return REF;
  	}
docs: Returns {@link #REF} if a reference to a previously read object was read, which is stored in {@link #readObject}. Returns a
  stack size (> 0) if a reference ID has been put on the stack.