This is an automated email from the ASF dual-hosted git repository.

sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere-elasticjob.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b9aab879 Add exception declaration of @SneakyThrows (#2335)
0b9aab879 is described below

commit 0b9aab879a38adae1faa3e6e3bacd0ad1f2b60ab
Author: Liang Zhang <[email protected]>
AuthorDate: Sun Oct 29 13:47:25 2023 +0800

    Add exception declaration of @SneakyThrows (#2335)
---
 .../error/handler/dingtalk/DingtalkJobErrorHandler.java    |  4 ++--
 .../dingtalk/fixture/DingtalkInternalController.java       |  4 ++--
 .../error/handler/wechat/WechatJobErrorHandler.java        |  4 ++--
 .../handler/wechat/fixture/WechatInternalController.java   |  6 ++----
 .../tracing/rdb/storage/RDBStorageSQLMapper.java           |  3 ++-
 .../shardingsphere/elasticjob/infra/env/IpUtilsTest.java   | 14 +++++---------
 .../reg/zookeeper/ZookeeperElectionServiceTest.java        |  2 --
 .../elasticjob/restful/NettyRestfulService.java            |  2 +-
 .../restful/pipeline/FilterChainInboundHandlerTest.java    |  2 --
 .../elasticjob/restful/pipeline/HttpClient.java            |  2 +-
 .../restful/pipeline/NettyRestfulServiceTest.java          |  5 ++---
 11 files changed, 19 insertions(+), 29 deletions(-)

diff --git 
a/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java
 
b/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java
index 175527e74..7fd77b094 100644
--- 
a/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java
+++ 
b/ecosystem/error-handler/type/dingtalk/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/DingtalkJobErrorHandler.java
@@ -131,7 +131,7 @@ public final class DingtalkJobErrorHandler implements 
JobErrorHandler {
     private String getErrorMessage(final String jobName, final Throwable 
cause) {
         StringWriter writer = new StringWriter();
         cause.printStackTrace(new PrintWriter(writer, true));
-        String result = String.format("Job '%s' exception occur in job 
processing, caused by %s", jobName, writer.toString());
+        String result = String.format("Job '%s' exception occur in job 
processing, caused by %s", jobName, writer);
         if (!Strings.isNullOrEmpty(keyword)) {
             result = keyword.concat(result);
         }
@@ -143,7 +143,7 @@ public final class DingtalkJobErrorHandler implements 
JobErrorHandler {
         return "DINGTALK";
     }
     
-    @SneakyThrows
+    @SneakyThrows(IOException.class)
     @Override
     public void close() {
         httpclient.close();
diff --git 
a/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java
 
b/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java
index 08572cacf..1c2c6c7d5 100644
--- 
a/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java
+++ 
b/ecosystem/error-handler/type/dingtalk/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/dingtalk/fixture/DingtalkInternalController.java
@@ -54,7 +54,6 @@ public final class DingtalkInternalController implements 
RestfulController {
      * @param body body
      * @return send result
      */
-    @SneakyThrows
     @Mapping(method = Http.POST, path = "/send")
     public String send(@Param(name = "access_token", source = 
ParamSource.QUERY) final String accessToken,
                        @Param(name = "timestamp", source = ParamSource.QUERY, 
required = false) final Long timestamp,
@@ -77,7 +76,8 @@ public final class DingtalkInternalController implements 
RestfulController {
         return GsonFactory.getGson().toJson(ImmutableMap.of("errcode", 0, 
"errmsg", "ok"));
     }
     
-    private String sign(final Long timestamp) throws NoSuchAlgorithmException, 
InvalidKeyException {
+    @SneakyThrows({NoSuchAlgorithmException.class, InvalidKeyException.class})
+    private String sign(final Long timestamp) {
         String stringToSign = timestamp + "\n" + SECRET;
         Mac mac = Mac.getInstance("HmacSHA256");
         mac.init(new SecretKeySpec(SECRET.getBytes(StandardCharsets.UTF_8), 
"HmacSHA256"));
diff --git 
a/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java
 
b/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java
index 64db934c2..496e28d03 100644
--- 
a/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java
+++ 
b/ecosystem/error-handler/type/wechat/src/main/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/WechatJobErrorHandler.java
@@ -99,7 +99,7 @@ public final class WechatJobErrorHandler implements 
JobErrorHandler {
     private String getErrorMessage(final String jobName, final Throwable 
cause) {
         StringWriter stringWriter = new StringWriter();
         cause.printStackTrace(new PrintWriter(stringWriter, true));
-        return String.format("Job '%s' exception occur in job processing, 
caused by %s", jobName, stringWriter.toString());
+        return String.format("Job '%s' exception occur in job processing, 
caused by %s", jobName, stringWriter);
     }
     
     @Override
@@ -107,7 +107,7 @@ public final class WechatJobErrorHandler implements 
JobErrorHandler {
         return "WECHAT";
     }
     
-    @SneakyThrows
+    @SneakyThrows(IOException.class)
     @Override
     public void close() {
         httpclient.close();
diff --git 
a/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/fixture/WechatInternalController.java
 
b/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/fixture/WechatInternalController.java
index 4acf631c6..90d572abe 100644
--- 
a/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/fixture/WechatInternalController.java
+++ 
b/ecosystem/error-handler/type/wechat/src/test/java/org/apache/shardingsphere/elasticjob/error/handler/wechat/fixture/WechatInternalController.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.elasticjob.error.handler.wechat.fixture;
 
 import com.google.common.collect.ImmutableMap;
-import lombok.SneakyThrows;
 import org.apache.shardingsphere.elasticjob.infra.json.GsonFactory;
 import org.apache.shardingsphere.elasticjob.restful.Http;
 import org.apache.shardingsphere.elasticjob.restful.RestfulController;
@@ -31,12 +30,11 @@ public final class WechatInternalController implements 
RestfulController {
     private static final String KEY = "mocked_key";
     
     /**
-     * Send wechat message.
+     * Send Wechat message.
      *
      * @param key access token
-     * @return send Result
+     * @return send result
      */
-    @SneakyThrows
     @Mapping(method = Http.POST, path = "/send")
     public String send(@Param(name = "key", source = ParamSource.QUERY) final 
String key) {
         if (!KEY.equals(key)) {
diff --git 
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
 
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
index e3751336f..63e55d21b 100644
--- 
a/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
+++ 
b/ecosystem/tracing/rdb/src/main/java/org/apache/shardingsphere/elasticjob/tracing/rdb/storage/RDBStorageSQLMapper.java
@@ -20,6 +20,7 @@ package 
org.apache.shardingsphere.elasticjob.tracing.rdb.storage;
 import lombok.Getter;
 import lombok.SneakyThrows;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
@@ -66,7 +67,7 @@ public final class RDBStorageSQLMapper {
         selectOriginalTaskIdForJobStatusTraceLog = 
props.getProperty("JOB_STATUS_TRACE_LOG.SELECT_ORIGINAL_TASK_ID");
     }
     
-    @SneakyThrows
+    @SneakyThrows(IOException.class)
     private Properties loadProps(final String sqlPropertiesFileName) {
         Properties result = new Properties();
         result.load(getPropertiesInputStream(sqlPropertiesFileName));
diff --git 
a/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java
 
b/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java
index 49fbe4a05..bb948c623 100644
--- 
a/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java
+++ 
b/infra/src/test/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtilsTest.java
@@ -17,9 +17,9 @@
 
 package org.apache.shardingsphere.elasticjob.infra.env;
 
-import lombok.SneakyThrows;
 import org.junit.jupiter.api.Test;
 
+import java.io.IOException;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.net.Inet4Address;
@@ -45,8 +45,7 @@ class IpUtilsTest {
     }
     
     @Test
-    @SneakyThrows
-    void assertPreferredNetworkInterface() {
+    void assertPreferredNetworkInterface() throws ReflectiveOperationException 
{
         System.setProperty(IpUtils.PREFERRED_NETWORK_INTERFACE, "eth0");
         Method declaredMethod = 
IpUtils.class.getDeclaredMethod("isPreferredNetworkInterface", 
NetworkInterface.class);
         declaredMethod.setAccessible(true);
@@ -58,8 +57,7 @@ class IpUtilsTest {
     }
     
     @Test
-    @SneakyThrows
-    void assertPreferredNetworkAddress() {
+    void assertPreferredNetworkAddress() throws ReflectiveOperationException {
         Method declaredMethod = 
IpUtils.class.getDeclaredMethod("isPreferredAddress", InetAddress.class);
         declaredMethod.setAccessible(true);
         InetAddress inetAddress = mock(InetAddress.class);
@@ -78,8 +76,7 @@ class IpUtilsTest {
     }
     
     @Test
-    @SneakyThrows
-    void assertGetFirstNetworkInterface() {
+    void assertGetFirstNetworkInterface() throws IOException, 
ReflectiveOperationException {
         InetAddress address1 = mock(Inet4Address.class);
         when(address1.isLoopbackAddress()).thenReturn(false);
         when(address1.isAnyLocalAddress()).thenReturn(false);
@@ -113,8 +110,7 @@ class IpUtilsTest {
     }
     
     @Test
-    @SneakyThrows
-    void assertGetHostName() {
+    void assertGetHostName() throws ReflectiveOperationException {
         assertNotNull(IpUtils.getHostName());
         Field field = IpUtils.class.getDeclaredField("cachedHostName");
         field.setAccessible(true);
diff --git 
a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
 
b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
index 50cecb141..440191c2e 100644
--- 
a/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
+++ 
b/registry-center/provider/zookeeper-curator/src/test/java/org/apache/shardingsphere/elasticjob/reg/zookeeper/ZookeeperElectionServiceTest.java
@@ -17,7 +17,6 @@
 
 package org.apache.shardingsphere.elasticjob.reg.zookeeper;
 
-import lombok.SneakyThrows;
 import org.apache.curator.framework.CuratorFramework;
 import org.apache.curator.framework.CuratorFrameworkFactory;
 import org.apache.curator.framework.recipes.leader.LeaderSelector;
@@ -85,7 +84,6 @@ class ZookeeperElectionServiceTest {
         Awaitility.await().pollDelay(100L, 
TimeUnit.MILLISECONDS).until(condition::get);
     }
     
-    @SneakyThrows
     private boolean hasLeadership(final ZookeeperElectionService 
zookeeperElectionService) {
         return ((LeaderSelector) 
ReflectionUtils.getFieldValue(zookeeperElectionService, 
"leaderSelector")).hasLeadership();
     }
diff --git 
a/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulService.java
 
b/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulService.java
index dfba296ad..a12c5a7dd 100644
--- 
a/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulService.java
+++ 
b/restful/src/main/java/org/apache/shardingsphere/elasticjob/restful/NettyRestfulService.java
@@ -55,7 +55,7 @@ public final class NettyRestfulService implements 
RestfulService {
                 .childHandler(new RestfulServiceChannelInitializer(config));
     }
     
-    @SneakyThrows
+    @SneakyThrows(InterruptedException.class)
     @Override
     public void startup() {
         initServerBootstrap();
diff --git 
a/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/FilterChainInboundHandlerTest.java
 
b/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/FilterChainInboundHandlerTest.java
index 67cc06654..5bc635c1a 100644
--- 
a/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/FilterChainInboundHandlerTest.java
+++ 
b/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/FilterChainInboundHandlerTest.java
@@ -18,7 +18,6 @@
 package org.apache.shardingsphere.elasticjob.restful.pipeline;
 
 import io.netty.channel.embedded.EmbeddedChannel;
-import lombok.SneakyThrows;
 import org.apache.shardingsphere.elasticjob.restful.Filter;
 import org.apache.shardingsphere.elasticjob.restful.handler.HandleContext;
 import org.apache.shardingsphere.elasticjob.restful.handler.Handler;
@@ -52,7 +51,6 @@ class FilterChainInboundHandlerTest {
     }
     
     @Test
-    @SneakyThrows
     void assertNoFilter() {
         when(filterInstances.isEmpty()).thenReturn(true);
         channel.writeOneInbound(handleContext);
diff --git 
a/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/HttpClient.java
 
b/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/HttpClient.java
index 2c2296d13..6c3805009 100644
--- 
a/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/HttpClient.java
+++ 
b/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/HttpClient.java
@@ -49,7 +49,7 @@ public final class HttpClient {
      * @param consumer HTTP response consumer
      * @param timeoutSeconds wait for consume
      */
-    @SneakyThrows
+    @SneakyThrows(InterruptedException.class)
     public static void request(final String host, final int port, final 
FullHttpRequest request, final Consumer<FullHttpResponse> consumer, final Long 
timeoutSeconds) {
         CountDownLatch countDownLatch = new CountDownLatch(1);
         EventLoopGroup eventLoopGroup = new NioEventLoopGroup();
diff --git 
a/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/NettyRestfulServiceTest.java
 
b/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/NettyRestfulServiceTest.java
index 446feaeba..eabf443a4 100644
--- 
a/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/NettyRestfulServiceTest.java
+++ 
b/restful/src/test/java/org/apache/shardingsphere/elasticjob/restful/pipeline/NettyRestfulServiceTest.java
@@ -26,7 +26,6 @@ import io.netty.handler.codec.http.HttpHeaderValues;
 import io.netty.handler.codec.http.HttpMethod;
 import io.netty.handler.codec.http.HttpUtil;
 import io.netty.handler.codec.http.HttpVersion;
-import lombok.SneakyThrows;
 import org.apache.shardingsphere.elasticjob.restful.NettyRestfulService;
 import 
org.apache.shardingsphere.elasticjob.restful.NettyRestfulServiceConfiguration;
 import org.apache.shardingsphere.elasticjob.restful.RestfulService;
@@ -39,6 +38,7 @@ import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.Timeout;
 
+import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.nio.charset.StandardCharsets;
 import java.util.concurrent.TimeUnit;
@@ -67,10 +67,9 @@ class NettyRestfulServiceTest {
         restfulService.startup();
     }
     
-    @SneakyThrows
     @Test
     @Timeout(value = TESTCASE_TIMEOUT, unit = TimeUnit.MILLISECONDS)
-    void assertRequestWithParameters() {
+    void assertRequestWithParameters() throws UnsupportedEncodingException {
         String cron = "0 * * * * ?";
         String uri = String.format("/job/myGroup/myJob?cron=%s", 
URLEncoder.encode(cron, "UTF-8"));
         String description = "Descriptions about this job.";

Reply via email to