[FIX] 2 NPE

This commit is contained in:
Gravit 2020-03-01 14:18:54 +07:00
parent 6af348606b
commit a8b96a2adf
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
3 changed files with 26 additions and 4 deletions

View file

@ -63,7 +63,7 @@ public void invoke(String... args) throws Exception {
public abstract void ban(List<HWID> hwid) throws HWIDException;
public void check(HWID hwid, String username) throws HWIDException {
if (hwid.isNull()) return;
if (hwid == null || hwid.isNull()) return;
check0(hwid, username);
}

View file

@ -66,6 +66,11 @@ public WebSocketService(ChannelGroup channels, LaunchServer server) {
public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) {
String request = frame.text();
WebSocketServerResponse response = gson.fromJson(request, WebSocketServerResponse.class);
if(response == null)
{
RequestEvent event= new ErrorRequestEvent("This type of request is not supported");
sendObject(ctx, event);
}
process(ctx, response, client, ip);
}

View file

@ -15,24 +15,41 @@ public class UniversalJsonAdapter<R> implements JsonSerializer<R>, JsonDeseriali
public final ProviderMap<R> providerMap;
public final String name;
public final String PROP_NAME;
public final boolean printErrorIfUnknownType;
public UniversalJsonAdapter(ProviderMap<R> providerMap) {
this.providerMap = providerMap;
this.name = providerMap.getName();
this.PROP_NAME = "type";
printErrorIfUnknownType = true;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String PROP_NAME) {
this.providerMap = providerMap;
this.name = providerMap.getName();
this.PROP_NAME = PROP_NAME;
printErrorIfUnknownType = true;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String name, String PROP_NAME, boolean printErrorIfUnknownType) {
this.providerMap = providerMap;
this.name = name;
this.PROP_NAME = PROP_NAME;
this.printErrorIfUnknownType = printErrorIfUnknownType;
}
public UniversalJsonAdapter(ProviderMap<R> providerMap, String name, boolean printErrorIfUnknownType) {
this.providerMap = providerMap;
this.name = name;
this.PROP_NAME = "type";
this.printErrorIfUnknownType = printErrorIfUnknownType;
}
public R deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
String typename = json.getAsJsonObject().getAsJsonPrimitive(PROP_NAME).getAsString();
Class<? extends R> cls = providerMap.getClass(typename);
if (cls == null) {
LogHelper.error("%s %s not found", name, typename);
if(printErrorIfUnknownType) LogHelper.error("%s %s not found", name, typename);
return null;
}
return context.deserialize(json, cls);
@ -48,9 +65,9 @@ public JsonElement serialize(R src, Type typeOfSrc, JsonSerializationContext con
}
if(classPath == null)
{
LogHelper.warning("Class %s type null", src.getClass());
if(printErrorIfUnknownType) LogHelper.warning("Class %s type null", src.getClass());
}
jo.add(PROP_NAME, new JsonPrimitive(classPath));
else jo.add(PROP_NAME, new JsonPrimitive(classPath));
return jo;
}