mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
Apply pmd plugin and fix/ignore broken styles
This commit applies [p3c-pmd](https://github.com/alibaba/p3c) plugin/rules, and fixes/ignores all violations of piority 1 (mandatory).
This commit is contained in:
@@ -47,6 +47,7 @@ import java.util.TimerTask;
|
||||
" dashboard -n 10\n" +
|
||||
" dashboard -i 2000\n" +
|
||||
Constants.WIKI + Constants.WIKI_HOME + "dashboard")
|
||||
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||
public class DashboardCommand extends AnnotatedCommand {
|
||||
|
||||
private static final Logger logger = LogUtil.getArthasLogger();
|
||||
|
||||
+1
@@ -8,6 +8,7 @@ import java.util.Timer;
|
||||
/**
|
||||
* @author ralf0131 2017-01-09 13:37.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||
public class DashboardInterruptHandler extends CommandInterruptHandler {
|
||||
|
||||
private volatile Timer timer;
|
||||
|
||||
+1
@@ -66,6 +66,7 @@ import static com.taobao.text.ui.Element.label;
|
||||
*
|
||||
* @author beiwei30 on 28/11/2016.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||
class MonitorAdviceListener extends ReflectAdviceListenerAdapter {
|
||||
// 输出定时任务
|
||||
private Timer timer;
|
||||
|
||||
@@ -40,6 +40,7 @@ public class ArthasBootstrap {
|
||||
private ShellServer shellServer;
|
||||
private ExecutorService executorService;
|
||||
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
private ArthasBootstrap(int pid, Instrumentation instrumentation) {
|
||||
this.pid = pid;
|
||||
this.instrumentation = instrumentation;
|
||||
|
||||
@@ -146,6 +146,7 @@ public class ShellServerImpl extends ShellServer {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
public synchronized void setTimer() {
|
||||
if (!closed && reaperInterval > 0) {
|
||||
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import com.taobao.middleware.logger.Logger;
|
||||
* @author gehui 2017年7月31日 上午11:55:41
|
||||
*/
|
||||
public class GlobalJobControllerImpl extends JobControllerImpl {
|
||||
|
||||
@SuppressWarnings("PMD.AvoidUseTimerRule")
|
||||
private Timer timer = new Timer("job-timeout", true);
|
||||
private Map<Integer, TimerTask> jobTimeoutTaskMap = new HashMap<Integer, TimerTask>();
|
||||
private static final Logger logger = LogUtil.getArthasLogger();
|
||||
|
||||
@@ -85,14 +85,16 @@ public class Decompiler {
|
||||
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();
|
||||
}
|
||||
@@ -105,8 +107,9 @@ public class Decompiler {
|
||||
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 {
|
||||
@@ -132,12 +135,14 @@ public class Decompiler {
|
||||
// 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 + "'.");
|
||||
}
|
||||
@@ -146,18 +151,21 @@ public class Decompiler {
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -191,12 +191,13 @@ public class NetUtils {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
} finally {
|
||||
if (s != null)
|
||||
if (s != null) {
|
||||
try {
|
||||
s.close();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -871,7 +871,9 @@ public abstract class StringUtils {
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -881,7 +883,9 @@ public abstract class StringUtils {
|
||||
* @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);
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.concurrent.Executors;
|
||||
* Created by zhuyong on 15/11/12.
|
||||
*/
|
||||
public class UserStatUtil {
|
||||
@SuppressWarnings("PMD.ThreadPoolCreationRule")
|
||||
private static final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
private static final String ip = IPUtils.getLocalIP();
|
||||
|
||||
|
||||
@@ -136,7 +136,9 @@ public class Ansi {
|
||||
};
|
||||
|
||||
public static void setDetector(final Callable<Boolean> detector) {
|
||||
if (detector == null) throw new IllegalArgumentException();
|
||||
if (detector == null) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
Ansi.detector = detector;
|
||||
}
|
||||
|
||||
@@ -698,8 +700,9 @@ public class Ansi {
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user