Skip to content

Commit

Permalink
polish alibaba#568
Browse files Browse the repository at this point in the history
  • Loading branch information
hengyunabc committed Mar 14, 2019
2 parents 17c42f3 + ae67e7e commit 6f990a2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
24 changes: 16 additions & 8 deletions core/src/main/java/com/taobao/arthas/core/util/Decompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ public static String decompile(String classFilePath, String methodName) {
path = classFileSource.adjustInputPath(path);

AnalysisType type = (AnalysisType) options.getOption(OptionsImpl.ANALYSE_AS);
if (type == null)
if (type == null) {
type = dcCommonState.detectClsJar(path);
}

if (type == AnalysisType.JAR) {
// doJar(dcCommonState, path, dumperFactory);
}
if (type == AnalysisType.CLASS)
if (type == AnalysisType.CLASS) {
result.append(doClass(dcCommonState, path, skipInnerClass, dumperFactory));
}
}
return result.toString();
}
Expand All @@ -105,8 +107,9 @@ public static String doClass(DCCommonState dcCommonState, String path, boolean s
Dumper d = new ToStringDumper();
try {
ClassFile c = dcCommonState.getClassFileMaybePath(path);
if ((skipInnerClass) && (c.isInnerClass()))
if ((skipInnerClass) && (c.isInnerClass())) {
return "";
}
dcCommonState.configureWith(c);
dumperFactory.getProgressDumper().analysingType(c.getClassType());
try {
Expand All @@ -132,12 +135,14 @@ public static String doClass(DCCommonState dcCommonState, String path, boolean s
// collectingDumper.getTypeUsageInformation(), illegalIdentifierDump);

String methname = (String) options.getOption(OptionsImpl.METHODNAME);
if (methname == null)
if (methname == null) {
c.dump(d);
}
else {
try {
for (Method method : c.getMethodByName(methname))
for (Method method : c.getMethodByName(methname)) {
method.dump(d, true);
}
} catch (NoSuchMethodException e) {
throw new IllegalArgumentException("No such method '" + methname + "'.");
}
Expand All @@ -146,18 +151,21 @@ public static String doClass(DCCommonState dcCommonState, String path, boolean s
result.append(d.toString());
} catch (ConfusedCFRException e) {
result.append(e.toString()).append("\n");
for (Object x : e.getStackTrace())
for (Object x : e.getStackTrace()) {
result.append(x).append("\n");
}
} catch (CannotLoadClassException e) {
result.append("Can't load the class specified:").append("\n");
result.append(e.toString()).append("\n");
} catch (RuntimeException e) {
result.append(e.toString()).append("\n");
for (Object x : e.getStackTrace())
for (Object x : e.getStackTrace()) {
result.append(x).append("\n");
}
} finally {
if (d != null)
if (d != null) {
d.close();
}
}
return result.toString();
}
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/taobao/arthas/core/util/NetUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ public static boolean serverListening(String host, int port) {
} catch (Exception e) {
return false;
} finally {
if (s != null)
if (s != null) {
try {
s.close();
} catch (Exception e) {
// ignore
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,9 @@ public static String stripEnd(final String str, final String stripChars) {
}

public static String classLoaderHash(Class<?> clazz) {
if (clazz == null || clazz.getClassLoader() == null) return "null";
if (clazz == null || clazz.getClassLoader() == null) {
return "null";
}
return Integer.toHexString(clazz.getClassLoader().hashCode());
}

Expand All @@ -881,7 +883,9 @@ public static String classLoaderHash(Class<?> clazz) {
* @return human readable format
*/
public static String humanReadableByteCount(long bytes) {
if (bytes < UNIT) return bytes + " B";
if (bytes < UNIT) {
return bytes + " B";
}
int exp = (int) (Math.log(bytes) / Math.log(UNIT));
String pre = STRING_UNITS.charAt(exp-1) + "i";
return String.format("%.2f %sB", bytes / Math.pow(UNIT, exp), pre);
Expand Down
7 changes: 5 additions & 2 deletions core/src/main/java/com/taobao/arthas/core/view/Ansi.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ public Boolean call() throws Exception {
};

public static void setDetector(final Callable<Boolean> detector) {
if (detector == null) throw new IllegalArgumentException();
if (detector == null) {
throw new IllegalArgumentException();
}
Ansi.detector = detector;
}

Expand Down Expand Up @@ -698,8 +700,9 @@ private Ansi appendEscapeSequence(char command, Object... options) {
}

private void flushAttributes() {
if (attributeOptions.isEmpty())
if (attributeOptions.isEmpty()) {
return;
}
if (attributeOptions.size() == 1 && attributeOptions.get(0) == 0) {
builder.append(FIRST_ESC_CHAR);
builder.append(SECOND_ESC_CHAR);
Expand Down

0 comments on commit 6f990a2

Please sign in to comment.