Skip to content

Commit b10c984

Browse files
author
daguimu
committed
feat: Optimize code and handle potential NullPointerExceptions
1 parent 2b6d331 commit b10c984

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

common/src/main/java/com/taobao/arthas/common/ExecutingCommand.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ public static List<String> runNative(String[] cmdToRunWithArgs) {
4444
Process p = null;
4545
try {
4646
p = Runtime.getRuntime().exec(cmdToRunWithArgs);
47-
} catch (SecurityException e) {
48-
AnsiLog.trace("Couldn't run command {}:", Arrays.toString(cmdToRunWithArgs));
49-
AnsiLog.trace(e);
50-
return new ArrayList<String>(0);
51-
} catch (IOException e) {
47+
} catch (SecurityException | IOException e) {
5248
AnsiLog.trace("Couldn't run command {}:", Arrays.toString(cmdToRunWithArgs));
5349
AnsiLog.trace(e);
5450
return new ArrayList<String>(0);

core/src/main/java/com/taobao/arthas/core/command/basic1000/JFRCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class JFRCommand extends AnnotatedCommand {
5959
private JFRModel result = new JFRModel();
6060
private static Map<Long, Recording> recordings = new ConcurrentHashMap<Long, Recording>();
6161

62-
@Argument(index = 0, argName = "cmd", required = true)
62+
@Argument(index = 0, argName = "cmd")
6363
@Description("command name (start status stop dump)")
6464
public void setCmd(String cmd) {
6565
this.cmd = cmd;
@@ -209,7 +209,7 @@ public void process(CommandProcess process) {
209209
}
210210
}
211211

212-
if (isDumpOnExit() != false) {
212+
if (isDumpOnExit()) {
213213
r.setDumpOnExit(isDumpOnExit().booleanValue());
214214
}
215215

@@ -256,6 +256,7 @@ public void process(CommandProcess process) {
256256
Recording r = recordings.get(getRecording());
257257
if (r == null) {
258258
process.end(-1, "recording not exit");
259+
return;
259260
}
260261
printRecording(r);
261262
} else {// list all recordings
@@ -308,6 +309,7 @@ public void process(CommandProcess process) {
308309
Recording r = recordings.remove(getRecording());
309310
if (r == null) {
310311
process.end(-1, "recording not exit");
312+
return;
311313
}
312314
if ("CLOSED".equals(r.getState().toString()) || "STOPPED".equals(r.getState().toString())) {
313315
process.end(-1, "Failed to stop recording, state can not be closed/stopped");

core/src/main/java/com/taobao/arthas/core/command/basic1000/KeymapCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void process(CommandProcess process) {
5151
String line;
5252
while ((line = br.readLine()) != null) {
5353
line = line.trim();
54-
if (line.startsWith("#") || "".equals(line)) {
54+
if (line.isEmpty() || line.startsWith("#")) {
5555
continue;
5656
}
5757
String[] strings = line.split(":");

core/src/main/java/com/taobao/arthas/core/command/klass100/OgnlCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class OgnlCommand extends AnnotatedCommand {
4646
private String classLoaderClass;
4747
private int expand = 1;
4848

49-
@Argument(argName = "express", index = 0, required = true)
49+
@Argument(argName = "express", index = 0)
5050
@Description("The ognl expression.")
5151
public void setExpress(String express) {
5252
this.express = express;

0 commit comments

Comments
 (0)