Skip to content

Commit 2468879

Browse files
author
zhanglei28
committed
fix bad smell
1 parent 1b1f550 commit 2468879

File tree

13 files changed

+32
-28
lines changed

13 files changed

+32
-28
lines changed

motan-benchmark/pom.xml

+2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
<properties>
3737
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
38+
<skip.jacoco>true</skip.jacoco>
39+
<sonar.skip>true</sonar.skip>
3840
</properties>
3941

4042
<dependencies>

motan-core/src/main/java/com/weibo/api/motan/admin/handler/FaultInjectCommandHandler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.weibo.api.motan.admin.handler;
22

33
import com.alibaba.fastjson.JSON;
4-
import com.alibaba.fastjson.JSONArray;
54
import com.alibaba.fastjson.JSONObject;
65
import com.weibo.api.motan.admin.AbstractAdminCommandHandler;
76
import com.weibo.api.motan.common.MotanConstants;
@@ -42,7 +41,7 @@ public String[] getCommandName() {
4241
protected void process(String command, Map<String, String> params, Map<String, String> attachments, JSONObject result) {
4342
if (commands[0].equals(command)) {
4443
String configs = params.get("configs");
45-
List<FaultInjectionFilter.FaultInjectionConfig> configList = JSONArray.parseArray(configs, FaultInjectionFilter.FaultInjectionConfig.class);
44+
List<FaultInjectionFilter.FaultInjectionConfig> configList = JSON.parseArray(configs, FaultInjectionFilter.FaultInjectionConfig.class);
4645
if (configList == null) {
4746
throw new MotanServiceException("param configs not correct");
4847
}

motan-core/src/main/java/com/weibo/api/motan/registry/support/DirectRegistry.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public DirectRegistry(URL url) {
4444
}
4545
} catch (Exception e) {
4646
throw new MotanFrameworkException(
47-
String.format("parse direct url error, invalid direct registry address %s, address should be ip1:port1,ip2:port2 ..."));
47+
String.format("parse direct url error, invalid direct registry address %s, address should be ip1:port1,ip2:port2 ...", address));
4848
}
4949
} else {
5050
registerDirectUrl(url.getHost(), url.getPort());

motan-core/src/main/java/com/weibo/api/motan/registry/support/command/RpcCommandUtil.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.weibo.api.motan.registry.support.command;
1818

19-
import com.alibaba.fastjson.JSONObject;
19+
import com.alibaba.fastjson.JSON;
2020
import com.google.common.collect.ImmutableMap;
2121
import com.google.common.collect.ImmutableSet;
2222
import com.weibo.api.motan.util.LoggerUtil;
@@ -37,7 +37,7 @@ public class RpcCommandUtil {
3737
*/
3838
public static RpcCommand stringToCommand(String commandString) {
3939
try {
40-
RpcCommand rpcCommand = JSONObject.parseObject(commandString, RpcCommand.class);
40+
RpcCommand rpcCommand = JSON.parseObject(commandString, RpcCommand.class);
4141
if (rpcCommand != null) {
4242
rpcCommand.sort();
4343
}
@@ -58,7 +58,7 @@ public static String commandToString(RpcCommand command) {
5858
if (command == null) {
5959
return null;
6060
}
61-
return JSONObject.toJSONString(command);
61+
return JSON.toJSONString(command);
6262
}
6363

6464
private static PatternEvaluator evaluator = new PatternEvaluator();

motan-core/src/main/java/com/weibo/api/motan/serialize/SimpleSerialization.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ public <T> T deserialize(byte[] bytes, Class<T> clz) throws IOException {
203203
private <T> T deserialize(GrowableByteBuffer buffer, Class<T> clz) throws IOException {
204204
byte type = buffer.get();
205205
switch (type) {
206-
default:
207-
break;
208206
case NULL:
209207
return null;
210208
case STRING:
@@ -242,6 +240,7 @@ private <T> T deserialize(GrowableByteBuffer buffer, Class<T> clz) throws IOExce
242240
if (clz == byte.class || clz == Byte.class || clz == Object.class) {
243241
return (T) readByte(buffer);
244242
}
243+
break;
245244
case INT16:
246245
if (clz == short.class || clz == Short.class || clz == Object.class) {
247246
return (T) readInt16(buffer);
@@ -283,6 +282,8 @@ private <T> T deserialize(GrowableByteBuffer buffer, Class<T> clz) throws IOExce
283282
return (T) readSet(buffer);
284283
}
285284
break;
285+
default:
286+
break;
286287
}
287288
throw new MotanServiceException("SimpleSerialization not support " + type + " with receiver type:" + clz);
288289
}

motan-core/src/main/java/com/weibo/api/motan/transport/async/MotanAsyncProcessor.java

+11-12
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,17 @@ public Set<String> getSupportedAnnotationTypes() {
5858

5959
@Override
6060
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
61-
if (roundEnv.processingOver()) {
62-
return true;
63-
}
64-
for (Element elem : roundEnv.getElementsAnnotatedWith(MotanAsync.class)) {
65-
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "MotanAsyncProcessor will process " + elem);
66-
try {
67-
writeAsyncClass(elem);
68-
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "MotanAsyncProcessor done for " + elem);
69-
} catch (Exception e) {
70-
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
71-
"MotanAsyncProcessor process " + elem + " fail. exception:" + e.getMessage());
72-
e.printStackTrace();
61+
if (!roundEnv.processingOver()) {
62+
for (Element elem : roundEnv.getElementsAnnotatedWith(MotanAsync.class)) {
63+
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "MotanAsyncProcessor will process " + elem);
64+
try {
65+
writeAsyncClass(elem);
66+
processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "MotanAsyncProcessor done for " + elem);
67+
} catch (Exception e) {
68+
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING,
69+
"MotanAsyncProcessor process " + elem + " fail. exception:" + e.getMessage());
70+
e.printStackTrace();
71+
}
7372
}
7473
}
7574
return true;

motan-core/src/main/java/com/weibo/api/motan/util/CollectionUtil.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929

3030
public class CollectionUtil {
31+
private static Random rnd = new Random();
3132

3233
@SuppressWarnings("rawtypes")
3334
public static boolean isEmpty(Collection collection) {
@@ -40,7 +41,6 @@ public static boolean isEmpty(Map map) {
4041
}
4142

4243
public static void shuffleByteArray(byte[] array) {
43-
Random rnd = new Random();
4444
for (int i = array.length - 1; i > 0; i--) {
4545
int index = rnd.nextInt(i + 1);
4646
// swap

motan-core/src/main/java/com/weibo/api/motan/util/ExceptionUtil.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.weibo.api.motan.util;
1818

19+
import com.alibaba.fastjson.JSON;
1920
import com.alibaba.fastjson.JSONObject;
2021
import com.weibo.api.motan.exception.*;
2122
import org.apache.commons.lang3.StringUtils;
@@ -101,7 +102,7 @@ public static String toMessage(Exception e) {
101102
public static MotanAbstractException fromMessage(String msg) {
102103
if (StringUtils.isNotBlank(msg)) {
103104
try {
104-
JSONObject jsonObject = JSONObject.parseObject(msg);
105+
JSONObject jsonObject = JSON.parseObject(msg);
105106
int type = jsonObject.getIntValue("errtype");
106107
int errcode = jsonObject.getIntValue("errcode");
107108
String errmsg = jsonObject.getString("errmsg");

motan-core/src/test/java/com/weibo/api/motan/proxy/RefererInvocationHandlerTest.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ public void testLocalMehtod() throws Exception{
8787
//local method
8888
Method method = TestServiceImpl.class.getMethod("toString");
8989
assertTrue(handler.isLocalMethod(method));
90+
String result = null;
9091
try {
91-
String result = (String)handler.invoke(null, method, null);
92-
assertEquals("{protocol:motan[motan://local:80/test?group=default_rpc, available:true]}", result);
92+
result = (String)handler.invoke(null, method, null);
9393
} catch (Throwable e) {
94-
assertTrue(false);
94+
fail(e.getMessage());
9595
}
96+
assertEquals("{protocol:motan[motan://local:80/test?group=default_rpc, available:true]}", result);
97+
9698

9799
method = TestServiceImpl.class.getMethod("hashCode");
98100
assertTrue(handler.isLocalMethod(method));

motan-demo/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<properties>
3737
<spring-boot.version>2.3.1.RELEASE</spring-boot.version>
3838
<skip.jacoco>true</skip.jacoco>
39+
<sonar.skip>true</sonar.skip>
3940
</properties>
4041

4142
<dependencies>

motan-extension/filter-extension/filter-opentracing/src/main/java/com/weibo/api/motan/filter/opentracing/OpenTracingContext.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static void setActiveSpan(Span span) {
4747
RpcContext.getContext().putAttribute(ACTIVE_SPAN, span);
4848
}
4949

50-
public void setTracerFactory(TracerFactory tracerFactory) {
50+
public static void setTracerFactory(TracerFactory tracerFactory) {
5151
OpenTracingContext.tracerFactory = tracerFactory;
5252
}
5353
}

motan-springsupport/src/main/java/com/weibo/api/motan/config/springsupport/MotanBeanDefinitionParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private static BeanDefinition parse(Element element, ParserContext parserContext
129129
|| setter.getParameterTypes().length != 1) {
130130
continue;
131131
}
132-
String property = (name.substring(3, 4).toLowerCase() + name.substring(4)).replaceAll("_", "-");
132+
String property = (name.substring(3, 4).toLowerCase() + name.substring(4)).replace("_", "-");
133133
props.add(property);
134134
if ("id".equals(property)) {
135135
bd.getPropertyValues().addPropertyValue("id", id);

motan-transport-netty4/src/main/java/com/weibo/api/motan/transport/netty4/http/Netty4HttpServer.java

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
*/
4545
public class Netty4HttpServer extends AbstractServer implements StatisticCallback {
4646
private HttpMessageHandler httpMessageHandler;
47-
private URL url;
4847
private Channel channel;
4948
private EventLoopGroup bossGroup;
5049
private EventLoopGroup workerGroup;

0 commit comments

Comments
 (0)