feat: Optimize code and handle potential NullPointerExceptions

pull/2911/head
daguimu 5 months ago
parent 2b6d331fa8
commit 5d0168f02b

@ -44,11 +44,7 @@ public class ExecutingCommand {
Process p = null;
try {
p = Runtime.getRuntime().exec(cmdToRunWithArgs);
} catch (SecurityException e) {
AnsiLog.trace("Couldn't run command {}:", Arrays.toString(cmdToRunWithArgs));
AnsiLog.trace(e);
return new ArrayList<String>(0);
} catch (IOException e) {
} catch (SecurityException | IOException e) {
AnsiLog.trace("Couldn't run command {}:", Arrays.toString(cmdToRunWithArgs));
AnsiLog.trace(e);
return new ArrayList<String>(0);

@ -59,7 +59,7 @@ public class JFRCommand extends AnnotatedCommand {
private JFRModel result = new JFRModel();
private static Map<Long, Recording> recordings = new ConcurrentHashMap<Long, Recording>();
@Argument(index = 0, argName = "cmd", required = true)
@Argument(index = 0, argName = "cmd")
@Description("command name (start status stop dump)")
public void setCmd(String cmd) {
this.cmd = cmd;
@ -209,7 +209,7 @@ public class JFRCommand extends AnnotatedCommand {
}
}
if (isDumpOnExit() != false) {
if (isDumpOnExit()) {
r.setDumpOnExit(isDumpOnExit().booleanValue());
}
@ -256,6 +256,7 @@ public class JFRCommand extends AnnotatedCommand {
Recording r = recordings.get(getRecording());
if (r == null) {
process.end(-1, "recording not exit");
return;
}
printRecording(r);
} else {// list all recordings
@ -308,6 +309,7 @@ public class JFRCommand extends AnnotatedCommand {
Recording r = recordings.remove(getRecording());
if (r == null) {
process.end(-1, "recording not exit");
return;
}
if ("CLOSED".equals(r.getState().toString()) || "STOPPED".equals(r.getState().toString())) {
process.end(-1, "Failed to stop recording, state can not be closed/stopped");

@ -51,7 +51,7 @@ public class KeymapCommand extends AnnotatedCommand {
String line;
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.startsWith("#") || "".equals(line)) {
if (line.isEmpty() || line.startsWith("#")) {
continue;
}
String[] strings = line.split(":");

@ -46,7 +46,7 @@ public class OgnlCommand extends AnnotatedCommand {
private String classLoaderClass;
private int expand = 1;
@Argument(argName = "express", index = 0, required = true)
@Argument(argName = "express", index = 0)
@Description("The ognl expression.")
public void setExpress(String express) {
this.express = express;

Loading…
Cancel
Save