private InstanceId readReferenceOrNull (Input input, Class type, boolean mayBeNull) {
		if (type.isPrimitive()) type = getWrapperClass(type);
		boolean referencesSupported = useReferences(type);
		int id;
		if (mayBeNull) {
			id = input.readInt(true);
			if (id == NULL) {
				if (DEBUG) log("Read", null);
				instanceId.object = null;
				return instanceId;
			}
			if (!referencesSupported) return null;
		} else {
			if (!referencesSupported) return null;
			id = input.readInt(true);
		}
		instanceId.id = id;
		instanceId.type = type;
		Object object = instanceIdToObject.get(instanceId);
		if (object != null) {
			if (DEBUG) debug("kryo", "Read object reference " + id + ": " + string(object));
			instanceId.object = object;
			return instanceId;
		}
		if (TRACE) trace("kryo", "Read initial object reference " + id + ": " + className(type));
		return new InstanceId(type, id);
	}