Skip to content

Commit

Permalink
Fix potential NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Apr 10, 2022
1 parent e4300e7 commit ce262c6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Expand Up @@ -70,10 +70,10 @@ public void receive(SubDataClient client, ObjectMap<Integer> data) {
queue(host.getName(), () -> client.sendPacket(new PacketLinkExHost(0, null)));
setReady(client);
} else {
client.sendPacket(new PacketLinkExHost(3, "Host already linked"));
client.sendPacket(new PacketLinkExHost(3, "Host already linked: " + data.getString(0x0000)));
}
} else {
client.sendPacket(new PacketLinkExHost(4, "That host does not support a network interface"));
client.sendPacket(new PacketLinkExHost(4, "Requested host does not support network interfaces: " + data.getString(0x0000)));
}
} else {
client.sendPacket(new PacketLinkExHost(2, "There is no host with name: " + data.getString(0x0000)));
Expand Down
Expand Up @@ -81,7 +81,7 @@ public void receive(SubDataClient client, ObjectMap<Integer> data) {
queue(proxy.getName(), () -> client.sendPacket(new PacketLinkProxy(proxy.getName(), 0, null)));
setReady(client);
} else {
client.sendPacket(new PacketLinkProxy(proxy.getName(), 2, "Proxy already linked"));
client.sendPacket(new PacketLinkProxy(null, 2, "Proxy already linked: " + proxy.getName()));

}
} catch (Throwable e) {
Expand Down
Expand Up @@ -176,7 +176,7 @@ public void run() {
last = now;
setReady(client);
} else {
client.sendPacket(new PacketLinkServer(null, 4, "Server already linked"));
client.sendPacket(new PacketLinkServer(null, 4, "Server already linked: " + server.getName()));
}
}
}
Expand Up @@ -98,6 +98,7 @@ public SubServerImpl(ExHost host, String name, boolean enabled, int port, boolea

private void run() {
boolean falsestart = true;
int exit = Integer.MIN_VALUE;
allowrestart = true;
try {
ProcessBuilder pb = new ProcessBuilder().command(Executable.parse(host.host.getString("Git-Bash"), executable)).directory(directory);
Expand All @@ -121,15 +122,16 @@ private void run() {
queue.clear();

if (process.isAlive()) process.waitFor();
exit = process.exitValue();
} catch (IOException | InterruptedException e) {
host.log.error.println(e);
allowrestart = false;
if (falsestart) ((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExControlServer(this, Response.LAUNCH_EXCEPTION));
}

logger.destroy();
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) {
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExControlServer(this, Response.STOPPED, (Integer) process.exitValue(), (Boolean) allowrestart));
if (SubAPI.getInstance().getSubDataNetwork()[0] != null) { // noinspection UnnecessaryBoxing
((SubDataClient) SubAPI.getInstance().getSubDataNetwork()[0]).sendPacket(new PacketExControlServer(this, Response.STOPPED, Integer.valueOf(exit), Boolean.valueOf(allowrestart)));
}
host.log.info.println(name + " has stopped");
process = null;
Expand Down

0 comments on commit ce262c6

Please sign in to comment.