Skip to content

Commit b944430

Browse files
yqw570994511Aias00
andauthored
[type:refactor] Optimize code for assert keyword #5967 (#5968)
* [type:refactor] Optimize code for assert keyword #5967 Replace the code that uses the assert keyword for validation with a more commonly used approach. * [type:refactor] Optimize code for assert keyword #5967 Replace the code that uses the assert keyword for validation with a more commonly used approach. --------- Co-authored-by: yuqianwei <qq120405> Co-authored-by: aias00 <[email protected]>
1 parent 4a75fec commit b944430

File tree

27 files changed

+38
-37
lines changed

27 files changed

+38
-37
lines changed

shenyu-alert/src/main/java/org/apache/shenyu/alert/strategy/DingTalkRobotAlertNotifyStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void send(final AlertReceiverDTO receiver, final AlarmContent alert) {
5656
ResponseEntity<CommonRobotNotifyResp> responseEntity = getRestTemplate().postForEntity(webHookUrl,
5757
httpEntity, CommonRobotNotifyResp.class);
5858
if (responseEntity.getStatusCode() == HttpStatus.OK) {
59-
assert Objects.nonNull(responseEntity.getBody());
59+
Objects.requireNonNull(responseEntity.getBody());
6060
if (responseEntity.getBody().getErrCode() == 0) {
6161
log.debug("Send dingTalk webHook: {} Success", webHookUrl);
6262
} else {

shenyu-common/src/main/java/org/apache/shenyu/common/utils/GsonUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public Map<T, U> deserialize(final JsonElement json, final Type type, final Json
357357
}
358358

359359
Map<T, U> resultMap = null;
360-
assert Objects.nonNull(mapClass);
360+
Objects.requireNonNull(mapClass);
361361
if (Objects.requireNonNull(mapClass).isInterface()) {
362362
resultMap = new LinkedHashMap<>();
363363
} else {

shenyu-plugin/shenyu-plugin-ai-proxy/src/main/java/org/apache/shenyu/plugin/ai/proxy/AiProxyPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPlu
6363
aiProxyConfig = new AiProxyConfig();
6464
}
6565
final ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
66-
assert Objects.nonNull(shenyuContext);
66+
Objects.requireNonNull(shenyuContext);
6767

6868
// Get selector handle from cache
6969
AiProxyHandle selectorHandle = AiProxyPluginHandler.SELECTOR_CACHED_HANDLE.get()

shenyu-plugin/shenyu-plugin-ai-token-limiter/src/main/java/org/apache/shenyu/plugin/ai/token/limiter/redis/RedisConnectionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private GenericObjectPoolConfig<?> getPoolConfig(final RedisConfigProperties red
9292
protected final RedisStandaloneConfiguration redisStandaloneConfiguration(final RedisConfigProperties redisConfigProperties) {
9393
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
9494
String[] parts = StringUtils.split(redisConfigProperties.getUrl(), ":");
95-
assert Objects.nonNull(parts);
95+
Objects.requireNonNull(parts);
9696
config.setHostName(parts[0]);
9797
config.setPort(Integer.parseInt(parts[1]));
9898
if (Objects.nonNull(redisConfigProperties.getPassword())) {

shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/ShenyuPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ default boolean skip(ServerWebExchange exchange, RpcTypeEnum... rpcTypes) {
9797
return false;
9898
}
9999
ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
100-
assert Objects.nonNull(shenyuContext);
100+
Objects.requireNonNull(shenyuContext);
101101
return Arrays.stream(rpcTypes).anyMatch(type -> Objects.equals(shenyuContext.getRpcType(), type.getName()));
102102
}
103103

shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/RequestUrlUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static URI buildRequestUri(final ServerWebExchange exchange, final String
4848
path = path + rewriteUri;
4949
} else {
5050
ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
51-
assert Objects.nonNull(shenyuContext);
51+
Objects.requireNonNull(shenyuContext);
5252
String realUrl = shenyuContext.getRealUrl();
5353
if (StringUtils.isNoneBlank(realUrl)) {
5454
path = path + realUrl;
@@ -63,7 +63,7 @@ public static URI buildRequestUri(final ServerWebExchange exchange, final String
6363
if (StringUtils.isNotEmpty(uri.getQuery())) {
6464
path = path + "?" + uri.getQuery();
6565
}
66-
assert Objects.nonNull(path);
66+
Objects.requireNonNull(path);
6767
return UriComponentsBuilder.fromUriString(path).build(false).toUri();
6868
}
6969
}

shenyu-plugin/shenyu-plugin-api/src/main/java/org/apache/shenyu/plugin/api/utils/WebFluxResultUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public static Mono<Void> result(final ServerWebExchange exchange, final Object r
6464
}
6565
exchange.getResponse().getHeaders().setContentType(mediaType);
6666
final Object responseData = shenyuResult.result(exchange, resultData);
67-
assert Objects.nonNull(responseData);
67+
Objects.requireNonNull(responseData);
6868
final byte[] bytes = (responseData instanceof byte[])
6969
? (byte[]) responseData : responseData.toString().getBytes(StandardCharsets.UTF_8);
7070
return exchange.getResponse().writeWith(Mono.just(exchange.getResponse()

shenyu-plugin/shenyu-plugin-cache/shenyu-plugin-cache-redis/src/main/java/org/apache/shenyu/plugin/cache/redis/RedisConnectionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private GenericObjectPoolConfig<?> getPoolConfig(final RedisConfigProperties red
9292
protected final RedisStandaloneConfiguration redisStandaloneConfiguration(final RedisConfigProperties redisConfigProperties) {
9393
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
9494
String[] parts = StringUtils.split(redisConfigProperties.getUrl(), ":");
95-
assert Objects.nonNull(parts);
95+
Objects.requireNonNull(parts);
9696
config.setHostName(parts[0]);
9797
config.setPort(Integer.parseInt(parts[1]));
9898
if (Objects.nonNull(redisConfigProperties.getPassword())) {

shenyu-plugin/shenyu-plugin-context-path/src/main/java/org/apache/shenyu/plugin/context/path/ContextPathPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class ContextPathPlugin extends AbstractShenyuPlugin {
5050
@Override
5151
protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
5252
ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
53-
assert Objects.nonNull(shenyuContext);
53+
Objects.requireNonNull(shenyuContext);
5454
ContextMappingRuleHandle ruleHandle = buildRuleHandle(rule);
5555
if (Objects.isNull(ruleHandle)) {
5656
LOG.error("context path rule configuration is null :{}", rule);

shenyu-plugin/shenyu-plugin-fault-tolerance/shenyu-plugin-hystrix/src/main/java/org/apache/shenyu/plugin/hystrix/HystrixPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class HystrixPlugin extends AbstractShenyuPlugin {
5555
@Override
5656
protected Mono<Void> doExecute(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
5757
final ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
58-
assert Objects.nonNull(shenyuContext);
58+
Objects.requireNonNull(shenyuContext);
5959
final HystrixHandle hystrixHandle = HystrixPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
6060
String groupKey = hystrixHandle.getGroupKey();
6161
if (StringUtils.isBlank(hystrixHandle.getGroupKey())) {

0 commit comments

Comments
 (0)