Skip to content

Commit

Permalink
feat: Optimize code and handle potential NullPointerExceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
daguimu committed Sep 21, 2024
1 parent 2b6d331 commit 5d0168f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ public static List<String> runNative(String[] cmdToRunWithArgs) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,7 +209,7 @@ public void process(CommandProcess process) {
}
}

if (isDumpOnExit() != false) {
if (isDumpOnExit()) {
r.setDumpOnExit(isDumpOnExit().booleanValue());
}

Expand Down Expand Up @@ -256,6 +256,7 @@ public void process(CommandProcess process) {
Recording r = recordings.get(getRecording());
if (r == null) {
process.end(-1, "recording not exit");
return;
}
printRecording(r);
} else {// list all recordings
Expand Down Expand Up @@ -308,6 +309,7 @@ public void process(CommandProcess process) {
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void process(CommandProcess process) {
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(":");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 5d0168f

Please sign in to comment.