package edu.teco.dnd.module.messages.infoReq;

import java.lang.reflect.Type;
import java.util.UUID;

import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;

import edu.teco.dnd.module.Module;
import edu.teco.dnd.module.config.BlockTypeHolder;

public class ModuleInfoMessageAdapter implements JsonDeserializer<ModuleInfoMessage> {
	@Override
	public ModuleInfoMessage deserialize(final JsonElement json, final Type typeOfT,
			final JsonDeserializationContext context) throws JsonParseException {
		if (!json.isJsonObject()) {
			throw new JsonParseException("is not an object");
		}
		final JsonObject jsonObj = (JsonObject) json;
		final JsonElement jsonUUID = jsonObj.get("uuid");
		UUID uuid = context.deserialize(jsonUUID, UUID.class);
		final JsonElement jsonSourceUUID = jsonObj.get("sourceuuid");
		UUID sourceUUID = context.deserialize(jsonSourceUUID, UUID.class);
		final JsonElement jsonModule = jsonObj.get("module");
		Module module = context.deserialize(jsonModule, Module.class);
		setParents(module.getHolder());
		return new ModuleInfoMessage(sourceUUID, uuid, module);
	}

	private static void setParents(final BlockTypeHolder blockTypeHolder) {
		if (!blockTypeHolder.isLeave()) {
			for (final BlockTypeHolder child : blockTypeHolder.getChildren()) {
				child.setParent(blockTypeHolder);
				setParents(child);
			}
		}
	}
}

@@ -1146,39 +1146,121 @@
 ;%0A%09%09
-setParents(module.getHolder());
+final BlockTypeHolder rootHolder = module.getHolder();%0A%09%09if (rootHolder != null) %7B%0A%09%09%09setParents(rootHolder);%0A%09%09%7D
 %0A%09%09r

Fix NPE if Module doesn't send BTH