mirror of
https://github.com/alibaba/arthas.git
synced 2024-04-21 10:21:39 +00:00
simplify condition (#1977)
This commit is contained in:
@@ -1065,7 +1065,7 @@ class Telnet extends SocketClient
|
||||
_output_.flush();
|
||||
}
|
||||
aytMonitor.wait(timeout);
|
||||
if (aytFlag == false)
|
||||
if (!aytFlag)
|
||||
{
|
||||
retValue = false;
|
||||
aytFlag = true;
|
||||
|
||||
@@ -115,7 +115,7 @@ public class FileUtils {
|
||||
if (file.isDirectory()) {
|
||||
throw new IOException("File '" + file + "' exists but is a directory");
|
||||
}
|
||||
if (file.canWrite() == false) {
|
||||
if (!file.canWrite()) {
|
||||
throw new IOException("File '" + file + "' cannot be written to");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -79,7 +79,7 @@ public class GlobalOptions {
|
||||
summary = "Option to control include default method in interface when class matching",
|
||||
description = "This option disable to include default method in interface when matching class."
|
||||
)
|
||||
public static volatile boolean isSupportDefaultMethod = true && JavaVersionUtils.isGreaterThanJava7();
|
||||
public static volatile boolean isSupportDefaultMethod = JavaVersionUtils.isGreaterThanJava7();
|
||||
|
||||
/**
|
||||
* 是否日志中保存命令执行结果
|
||||
|
||||
@@ -60,32 +60,30 @@ public class AdviceListenerManager {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (adviceListenerMap != null) {
|
||||
for (Entry<ClassLoader, ClassLoaderAdviceListenerManager> entry : adviceListenerMap.entrySet()) {
|
||||
ClassLoaderAdviceListenerManager adviceListenerManager = entry.getValue();
|
||||
synchronized (adviceListenerManager) {
|
||||
for (Entry<String, List<AdviceListener>> eee : adviceListenerManager.map.entrySet()) {
|
||||
List<AdviceListener> listeners = eee.getValue();
|
||||
List<AdviceListener> newResult = new ArrayList<AdviceListener>();
|
||||
for (AdviceListener listener : listeners) {
|
||||
if (listener instanceof ProcessAware) {
|
||||
ProcessAware processAware = (ProcessAware) listener;
|
||||
Process process = processAware.getProcess();
|
||||
if (process == null) {
|
||||
continue;
|
||||
}
|
||||
ExecStatus status = process.status();
|
||||
if (!status.equals(ExecStatus.TERMINATED)) {
|
||||
newResult.add(listener);
|
||||
}
|
||||
for (Entry<ClassLoader, ClassLoaderAdviceListenerManager> entry : adviceListenerMap.entrySet()) {
|
||||
ClassLoaderAdviceListenerManager adviceListenerManager = entry.getValue();
|
||||
synchronized (adviceListenerManager) {
|
||||
for (Entry<String, List<AdviceListener>> eee : adviceListenerManager.map.entrySet()) {
|
||||
List<AdviceListener> listeners = eee.getValue();
|
||||
List<AdviceListener> newResult = new ArrayList<AdviceListener>();
|
||||
for (AdviceListener listener : listeners) {
|
||||
if (listener instanceof ProcessAware) {
|
||||
ProcessAware processAware = (ProcessAware) listener;
|
||||
Process process = processAware.getProcess();
|
||||
if (process == null) {
|
||||
continue;
|
||||
}
|
||||
ExecStatus status = process.status();
|
||||
if (!status.equals(ExecStatus.TERMINATED)) {
|
||||
newResult.add(listener);
|
||||
}
|
||||
}
|
||||
|
||||
if (newResult.size() != listeners.size()) {
|
||||
adviceListenerManager.map.put(eee.getKey(), newResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (newResult.size() != listeners.size()) {
|
||||
adviceListenerManager.map.put(eee.getKey(), newResult);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class Enhancer implements ClassFileTransformer {
|
||||
interceptorProcessors.addAll(defaultInterceptorClassParser.parse(SpyInterceptor3.class));
|
||||
|
||||
if (this.isTracing) {
|
||||
if (this.skipJDKTrace == false) {
|
||||
if (!this.skipJDKTrace) {
|
||||
interceptorProcessors.addAll(defaultInterceptorClassParser.parse(SpyTraceInterceptor1.class));
|
||||
interceptorProcessors.addAll(defaultInterceptorClassParser.parse(SpyTraceInterceptor2.class));
|
||||
interceptorProcessors.addAll(defaultInterceptorClassParser.parse(SpyTraceInterceptor3.class));
|
||||
|
||||
@@ -49,7 +49,7 @@ public class HistoryCommand extends AnnotatedCommand {
|
||||
Session session = process.session();
|
||||
//TODO 修改term history实现方式,统一使用HistoryManager
|
||||
Object termObject = session.get(Session.TTY);
|
||||
if (termObject != null && termObject instanceof TermImpl) {
|
||||
if (termObject instanceof TermImpl) {
|
||||
TermImpl term = (TermImpl) termObject;
|
||||
Readline readline = term.getReadline();
|
||||
List<int[]> history = readline.getHistory();
|
||||
|
||||
@@ -55,7 +55,7 @@ public class KeymapCommand extends AnnotatedCommand {
|
||||
continue;
|
||||
}
|
||||
String[] strings = line.split(":");
|
||||
if (strings != null && strings.length == 2) {
|
||||
if (strings.length == 2) {
|
||||
table.row(strings[0], translate(strings[0]), strings[1]);
|
||||
} else {
|
||||
table.row(line);
|
||||
|
||||
@@ -44,7 +44,7 @@ public class OgnlExpress implements Express {
|
||||
@Override
|
||||
public boolean is(String express) throws ExpressException {
|
||||
final Object ret = get(express);
|
||||
return null != ret && ret instanceof Boolean && (Boolean) ret;
|
||||
return ret instanceof Boolean && (Boolean) ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -136,7 +136,7 @@ public class ClassLoaderCommand extends AnnotatedCommand {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (targetClassLoader == null && classLoaderClass != null) {
|
||||
} else if (classLoaderClass != null) {
|
||||
List<ClassLoader> matchedClassLoaders = ClassLoaderUtils.getClassLoaderByClassName(inst, classLoaderClass);
|
||||
if (matchedClassLoaders.size() == 1) {
|
||||
targetClassLoader = matchedClassLoaders.get(0);
|
||||
|
||||
@@ -417,7 +417,7 @@ public class MBeanCommand extends AnnotatedCommand {
|
||||
logger.error("read mbean attribute failed: objectName={}, attributeName={}", objectName, attributeName, e);
|
||||
String errorStr;
|
||||
Throwable cause = e.getCause();
|
||||
if (cause != null && cause instanceof UnsupportedOperationException) {
|
||||
if (cause instanceof UnsupportedOperationException) {
|
||||
errorStr = "Unsupported";
|
||||
} else {
|
||||
errorStr = "Failure";
|
||||
|
||||
+1
-2
@@ -256,8 +256,7 @@ class MonitorAdviceListener extends AdviceListenerAdapter {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (null == obj
|
||||
|| !(obj instanceof Key)) {
|
||||
if (!(obj instanceof Key)) {
|
||||
return false;
|
||||
}
|
||||
Key okey = (Key) obj;
|
||||
|
||||
@@ -503,11 +503,9 @@ public class ProfilerCommand extends AnnotatedCommand {
|
||||
}
|
||||
String lines[] = execute.split("\\r?\\n");
|
||||
|
||||
if (lines != null) {
|
||||
for (String line : lines) {
|
||||
if (line.startsWith(" ")) {
|
||||
result.add(line.trim());
|
||||
}
|
||||
for (String line : lines) {
|
||||
if (line.startsWith(" ")) {
|
||||
result.add(line.trim());
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -21,14 +21,13 @@ public class BinderUtils {
|
||||
}
|
||||
|
||||
public static void inject(Environment environment, String parentPrefix, String prefix, Object instance) {
|
||||
if (prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
Class<? extends Object> type = instance.getClass();
|
||||
try {
|
||||
Config annotation = type.getAnnotation(Config.class);
|
||||
|
||||
if (prefix == null) {
|
||||
prefix = "";
|
||||
}
|
||||
|
||||
if (annotation == null) {
|
||||
prefix = parentPrefix + '.' + prefix;
|
||||
} else {
|
||||
@@ -41,22 +40,19 @@ public class BinderUtils {
|
||||
}
|
||||
|
||||
Method[] declaredMethods = type.getDeclaredMethods();
|
||||
if (declaredMethods != null) {
|
||||
// 获取到所有setter方法,再提取出field。根据前缀从 properties里取出值,再尝试用setter方法注入到对象里
|
||||
for (Method method : declaredMethods) {
|
||||
String methodName = method.getName();
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
// 获取到所有setter方法,再提取出field。根据前缀从 properties里取出值,再尝试用setter方法注入到对象里
|
||||
for (Method method : declaredMethods) {
|
||||
String methodName = method.getName();
|
||||
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||
|
||||
if (parameterTypes != null && parameterTypes.length == 1 && methodName.startsWith("set")
|
||||
&& methodName.length() > "set".length()) {
|
||||
if (parameterTypes.length == 1 && methodName.startsWith("set") && methodName.length() > "set".length()) {
|
||||
|
||||
String field = getFieldNameFromSetterMethod(methodName);
|
||||
String configKey = prefix + '.' + field;
|
||||
if (environment.containsProperty(configKey)) {
|
||||
Object reslovedValue = environment.getProperty(prefix + '.' + field, parameterTypes[0]);
|
||||
if (reslovedValue != null) {
|
||||
method.invoke(instance, new Object[] { reslovedValue });
|
||||
}
|
||||
String field = getFieldNameFromSetterMethod(methodName);
|
||||
String configKey = prefix + '.' + field;
|
||||
if (environment.containsProperty(configKey)) {
|
||||
Object reslovedValue = environment.getProperty(prefix + '.' + field, parameterTypes[0]);
|
||||
if (reslovedValue != null) {
|
||||
method.invoke(instance, new Object[] { reslovedValue });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,28 +64,26 @@ public class BinderUtils {
|
||||
|
||||
// process @NestedConfig
|
||||
Field[] fields = type.getDeclaredFields();
|
||||
if (fields != null) {
|
||||
for (Field field : fields) {
|
||||
NestedConfig nestedConfig = field.getAnnotation(NestedConfig.class);
|
||||
if (nestedConfig != null) {
|
||||
String prefixForField = field.getName();
|
||||
if (parentPrefix != null && prefix.length() > 0) {
|
||||
prefixForField = prefix + '.' + prefixForField;
|
||||
}
|
||||
for (Field field : fields) {
|
||||
NestedConfig nestedConfig = field.getAnnotation(NestedConfig.class);
|
||||
if (nestedConfig != null) {
|
||||
String prefixForField = field.getName();
|
||||
if (parentPrefix != null && prefix.length() > 0) {
|
||||
prefixForField = prefix + '.' + prefixForField;
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object fieldValue = field.get(instance);
|
||||
if (fieldValue == null) {
|
||||
fieldValue = field.getType().newInstance();
|
||||
}
|
||||
inject(environment, prefix, prefixForField, fieldValue);
|
||||
|
||||
field.set(instance, fieldValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("process @NestedConfig error, field: " + field + ", prefix: "
|
||||
+ prefix + ", instance: " + instance, e);
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
Object fieldValue = field.get(instance);
|
||||
if (fieldValue == null) {
|
||||
fieldValue = field.getType().newInstance();
|
||||
}
|
||||
inject(environment, prefix, prefixForField, fieldValue);
|
||||
|
||||
field.set(instance, fieldValue);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("process @NestedConfig error, field: " + field + ", prefix: "
|
||||
+ prefix + ", instance: " + instance, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ public class CompletionUtils {
|
||||
}
|
||||
|
||||
Set<Class<?>> results = SearchUtils.searchClassOnly(completion.session().getInstrumentation(), className, 2);
|
||||
if (results.isEmpty() || results.size() > 1) {
|
||||
if (results.size() != 1) {
|
||||
// no class found or multiple class found
|
||||
completion.complete(Collections.<String>emptyList());
|
||||
return true;
|
||||
|
||||
@@ -120,7 +120,7 @@ public class GrepHandler extends StdoutHandler {
|
||||
} else {
|
||||
match = pattern.matcher(line).find();
|
||||
}
|
||||
if (invertMatch ? !match : match) {
|
||||
if (invertMatch != match) {
|
||||
matchCount++;
|
||||
if (beforeLines > continueCount) {
|
||||
int n = lastContinueLineNum == -1 ? (beforeLines >= lineNum ? 1 : lineNum - beforeLines)
|
||||
|
||||
+3
-4
@@ -173,9 +173,8 @@ public class SessionManagerImpl implements SessionManager {
|
||||
*/
|
||||
public void evictConsumers(Session session) {
|
||||
SharingResultDistributor distributor = session.getResultDistributor();
|
||||
if (distributor != null && distributor instanceof SharingResultDistributor) {
|
||||
SharingResultDistributor sharingResultDistributor = (SharingResultDistributor) distributor;
|
||||
List<ResultConsumer> consumers = sharingResultDistributor.getConsumers();
|
||||
if (distributor != null) {
|
||||
List<ResultConsumer> consumers = distributor.getConsumers();
|
||||
//remove inactive consumer from session directly
|
||||
long now = System.currentTimeMillis();
|
||||
for (ResultConsumer consumer : consumers) {
|
||||
@@ -185,7 +184,7 @@ public class SessionManagerImpl implements SessionManager {
|
||||
logger.info("Removing inactive consumer from session, sessionId: {}, consumerId: {}, inactive duration: {}",
|
||||
session.getSessionId(), consumer.getConsumerId(), inactiveTime);
|
||||
consumer.appendResult(new MessageModel("consumer is inactive for a while, please refresh the page."));
|
||||
sharingResultDistributor.removeConsumer(consumer);
|
||||
distributor.removeConsumer(consumer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ public class HttpRequestHandler extends SimpleChannelInboundHandler<FullHttpRequ
|
||||
//try output dir later, avoid overlay classpath resources files
|
||||
if (response == null) {
|
||||
response = DirectoryBrowser.directView(dir, path, request, ctx);
|
||||
isFileResponseFinished = (response == null) ? false : true;
|
||||
isFileResponseFinished = response != null;
|
||||
}
|
||||
|
||||
//not found
|
||||
|
||||
@@ -738,7 +738,7 @@ public abstract class StringUtils {
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < strLen; i++) {
|
||||
if (Character.isWhitespace(cs.charAt(i)) == false) {
|
||||
if (!Character.isWhitespace(cs.charAt(i))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -926,12 +926,10 @@ public abstract class StringUtils {
|
||||
} catch (IOException exc) {
|
||||
// quit
|
||||
} finally {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -162,7 +162,7 @@ public class TypeRenderUtils {
|
||||
|
||||
public static FieldVO[] getFields(Class clazz) {
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
if (fields == null || fields.length == 0) {
|
||||
if (fields.length == 0) {
|
||||
return new FieldVO[0];
|
||||
}
|
||||
|
||||
|
||||
@@ -444,7 +444,7 @@ public class FieldUtils {
|
||||
}
|
||||
|
||||
static void isTrue(final boolean expression, final String message, final Object... values) {
|
||||
if (expression == false) {
|
||||
if (!expression) {
|
||||
throw new IllegalArgumentException(String.format(message, values));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,8 +79,7 @@ public class ClassInfoView implements View {
|
||||
final StringBuilder fieldSB = new StringBuilder();
|
||||
|
||||
final Field[] fields = clazz.getDeclaredFields();
|
||||
if (null != fields
|
||||
&& fields.length > 0) {
|
||||
if (fields.length > 0) {
|
||||
|
||||
for (Field field : fields) {
|
||||
|
||||
@@ -128,7 +127,7 @@ public class ClassInfoView implements View {
|
||||
final StringBuilder annotationSB = new StringBuilder();
|
||||
final Annotation[] annotationArray = clazz.getDeclaredAnnotations();
|
||||
|
||||
if (null != annotationArray && annotationArray.length > 0) {
|
||||
if (annotationArray.length > 0) {
|
||||
for (Annotation annotation : annotationArray) {
|
||||
annotationSB.append(StringUtils.classname(annotation.annotationType())).append(",");
|
||||
}
|
||||
@@ -145,7 +144,7 @@ public class ClassInfoView implements View {
|
||||
private String drawInterface() {
|
||||
final StringBuilder interfaceSB = new StringBuilder();
|
||||
final Class<?>[] interfaceArray = clazz.getInterfaces();
|
||||
if (null == interfaceArray || interfaceArray.length == 0) {
|
||||
if (interfaceArray.length == 0) {
|
||||
interfaceSB.append(Constants.EMPTY_STRING);
|
||||
} else {
|
||||
for (Class<?> i : interfaceArray) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class MethodInfoView implements View {
|
||||
final StringBuilder annotationSB = new StringBuilder();
|
||||
final Annotation[] annotationArray = method.getDeclaredAnnotations();
|
||||
|
||||
if (null != annotationArray && annotationArray.length > 0) {
|
||||
if (annotationArray.length > 0) {
|
||||
for (Annotation annotation : annotationArray) {
|
||||
annotationSB.append(StringUtils.classname(annotation.annotationType())).append(",");
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class MethodInfoView implements View {
|
||||
private String drawParameters() {
|
||||
final StringBuilder paramsSB = new StringBuilder();
|
||||
final Class<?>[] paramTypes = method.getParameterTypes();
|
||||
if (null != paramTypes && paramTypes.length > 0) {
|
||||
if (paramTypes.length > 0) {
|
||||
for (Class<?> clazz : paramTypes) {
|
||||
paramsSB.append(StringUtils.classname(clazz)).append("\n");
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class MethodInfoView implements View {
|
||||
private String drawExceptions() {
|
||||
final StringBuilder exceptionSB = new StringBuilder();
|
||||
final Class<?>[] exceptionTypes = method.getExceptionTypes();
|
||||
if (null != exceptionTypes && exceptionTypes.length > 0) {
|
||||
if (exceptionTypes.length > 0) {
|
||||
for (Class<?> clazz : exceptionTypes) {
|
||||
exceptionSB.append(StringUtils.classname(clazz)).append("\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user