From 9151aa89687f17da5506bd49014095c16e9bc2c1 Mon Sep 17 00:00:00 2001 From: Looly Date: Mon, 21 Feb 2022 01:15:04 +0800 Subject: [PATCH] fix bug --- CHANGELOG.md | 3 + .../hutool/core/exceptions/CheckedUtil.java | 142 +----------------- .../cn/hutool/core/net/SSLContextBuilder.java | 6 +- .../main/java/cn/hutool/core/net/SSLUtil.java | 4 +- .../core/exceptions/CheckedUtilTest.java | 1 - .../http/ssl/SSLSocketFactoryBuilder.java | 2 +- 6 files changed, 17 insertions(+), 141 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 711cb4eff..6e60eb77d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,13 @@ * 【extra 】 Ftp增加构造(issue#I4TKXP@gitee) * 【core 】 GenericBuilder支持Map构建(pr#540@Github) * 【json 】 新增TemporalAccessorSerializer +* 【core 】 使多个xxxBuilder实现Builder接口,扩展CheckedUtil(pr#545@Gitee) +* 【core 】 CheckedUtil删除第二个参数为RuntimeException的方法 ### 🐞Bug修复 * 【cache 】 修复ReentrantCache.toString方法线程不安全问题(issue#2140@Github) * 【core 】 修复SystemPropsUtil.getInt返回long问题(pr#546@Gitee) +* 【crypto 】 修复SM2.getD前导0问题(pr#2149@Github) ------------------------------------------------------------------------------------------------------------- # 5.7.21 (2022-02-14) diff --git a/hutool-core/src/main/java/cn/hutool/core/exceptions/CheckedUtil.java b/hutool-core/src/main/java/cn/hutool/core/exceptions/CheckedUtil.java index 3b76d8a78..ae595168a 100644 --- a/hutool-core/src/main/java/cn/hutool/core/exceptions/CheckedUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/exceptions/CheckedUtil.java @@ -54,7 +54,7 @@ public class CheckedUtil { * @return {@link FuncRt} */ public static FuncRt uncheck(Func expression) { - return uncheck(expression, new RuntimeException()); + return uncheck(expression, RuntimeException::new); } /** @@ -66,7 +66,7 @@ public class CheckedUtil { * @return {@link Func0Rt} */ public static Func0Rt uncheck(Func0 expression) { - return uncheck(expression, new RuntimeException()); + return uncheck(expression, RuntimeException::new); } /** @@ -79,7 +79,7 @@ public class CheckedUtil { * @return {@link Func1Rt} */ public static Func1Rt uncheck(Func1 expression) { - return uncheck(expression, new RuntimeException()); + return uncheck(expression, RuntimeException::new); } @@ -92,7 +92,7 @@ public class CheckedUtil { * @return {@link VoidFuncRt} */ public static

VoidFuncRt

uncheck(VoidFunc

expression) { - return uncheck(expression, new RuntimeException()); + return uncheck(expression, RuntimeException::new); } /** @@ -103,7 +103,7 @@ public class CheckedUtil { * @return {@link VoidFunc0Rt} */ public static VoidFunc0Rt uncheck(VoidFunc0 expression) { - return uncheck(expression, new RuntimeException()); + return uncheck(expression, RuntimeException::new); } /** @@ -115,36 +115,10 @@ public class CheckedUtil { * @return {@link VoidFunc1Rt} */ public static

VoidFunc1Rt

uncheck(VoidFunc1

expression) { - return uncheck(expression, new RuntimeException()); + return uncheck(expression, RuntimeException::new); } - /** - * 接收一个可以转化成 cn.hutool.core.lang.func.Func的Lambda表达式,和一个RuntimeException,当执行表达式抛出任何异常的时候,都会转化成运行时异常 - * 如此一来,代码中就不用显示的try-catch转化成运行时异常 - * - * @param expression Lambda表达式 - * @param rte 期望抛出的运行时异常 - * @param

运行时传入的参数类型 - * @param 最终返回的数据类型 - * @return {@link FuncRt} - */ - public static FuncRt uncheck(Func expression, RuntimeException rte) { - Objects.requireNonNull(expression, "expression can not be null"); - return t -> { - try { - return expression.call(t); - } catch (Exception e) { - if (rte == null) { - throw new RuntimeException(e); - } else { - rte.initCause(e); - throw rte; - } - } - }; - } - /** * 接收一个可以转化成 cn.hutool.core.lang.func.Func的Lambda表达式,和一个可以把Exception转化成RuntimeExceptionde的表达式,当执行表达式抛出任何异常的时候,都会转化成运行时异常 * 如此一来,代码中就不用显示的try-catch转化成运行时异常 @@ -170,31 +144,6 @@ public class CheckedUtil { }; } - /** - * 接收一个可以转化成 cn.hutool.core.lang.func.Func0的Lambda表达式,和一个RuntimeException,当执行表达式抛出任何异常的时候,都会转化成运行时异常 - * 如此一来,代码中就不用显示的try-catch转化成运行时异常 - * - * @param expression Lambda表达式 - * @param rte 期望抛出的运行时异常 - * @param 最终返回的数据类型 - * @return {@link Func0Rt} - */ - public static Func0Rt uncheck(Func0 expression, RuntimeException rte) { - Objects.requireNonNull(expression, "expression can not be null"); - return () -> { - try { - return expression.call(); - } catch (Exception e) { - if (rte == null) { - throw new RuntimeException(e); - } else { - rte.initCause(e); - throw rte; - } - } - }; - } - /** * 接收一个可以转化成 cn.hutool.core.lang.func.Func0的Lambda表达式,和一个可以把Exception转化成RuntimeExceptionde的表达式,当执行表达式抛出任何异常的时候,都会转化成运行时异常 * 如此一来,代码中就不用显示的try-catch转化成运行时异常 @@ -219,32 +168,6 @@ public class CheckedUtil { }; } - /** - * 接收一个可以转化成 cn.hutool.core.lang.func.Func1的Lambda表达式,和一个RuntimeException,当执行表达式抛出任何异常的时候,都会转化成运行时异常 - * 如此一来,代码中就不用显示的try-catch转化成运行时异常 - * - * @param expression Lambda表达式 - * @param rte 期望抛出的运行时异常 - * @param

运行时传入的参数类型 - * @param 最终返回的数据类型 - * @return {@link Func1Rt} - */ - public static Func1Rt uncheck(Func1 expression, RuntimeException rte) { - Objects.requireNonNull(expression, "expression can not be null"); - return t -> { - try { - return expression.call(t); - } catch (Exception e) { - if (rte == null) { - throw new RuntimeException(e); - } else { - rte.initCause(e); - throw rte; - } - } - }; - } - /** * 接收一个可以转化成 cn.hutool.core.lang.func.Func1的Lambda表达式,和一个可以把Exception转化成RuntimeExceptionde的表达式,当执行表达式抛出任何异常的时候,都会转化成运行时异常 * 如此一来,代码中就不用显示的try-catch转化成运行时异常 @@ -270,31 +193,6 @@ public class CheckedUtil { }; } - /** - * 接收一个可以转化成 cn.hutool.core.lang.func.VoidFunc的Lambda表达式,和一个可以把Exception转化成RuntimeExceptionde的表达式,当执行表达式抛出任何异常的时候,都会转化成运行时异常 - * 如此一来,代码中就不用显示的try-catch转化成运行时异常 - * - * @param expression Lambda表达式 - * @param rte 期望抛出的运行时异常 - * @param

运行时传入的参数类型 - * @return {@link VoidFuncRt} - */ - public static

VoidFuncRt

uncheck(VoidFunc

expression, RuntimeException rte) { - Objects.requireNonNull(expression, "expression can not be null"); - return t -> { - try { - expression.call(t); - } catch (Exception e) { - if (rte == null) { - throw new RuntimeException(e); - } else { - rte.initCause(e); - throw rte; - } - } - }; - } - /** * 接收一个可以转化成 cn.hutool.core.lang.func.VoidFunc的Lambda表达式,和一个可以把Exception转化成RuntimeExceptionde的表达式,当执行表达式抛出任何异常的时候,都会转化成运行时异常 * 如此一来,代码中就不用显示的try-catch转化成运行时异常 @@ -367,32 +265,6 @@ public class CheckedUtil { }; } - - /** - * 接收一个可以转化成 cn.hutool.core.lang.func.VoidFunc1的Lambda表达式,和一个RuntimeException,当执行表达式抛出任何异常的时候,都会转化成运行时异常 - * 如此一来,代码中就不用显示的try-catch转化成运行时异常 - * - * @param expression Lambda表达式 - * @param rte 期望抛出的运行时异常 - * @param

运行时传入的参数类型 - * @return {@link VoidFunc1Rt} - */ - public static

VoidFunc1Rt

uncheck(VoidFunc1

expression, RuntimeException rte) { - Objects.requireNonNull(expression, "expression can not be null"); - return t -> { - try { - expression.call(t); - } catch (Exception e) { - if (rte == null) { - throw new RuntimeException(e); - } else { - rte.initCause(e); - throw rte; - } - } - }; - } - /** * 接收一个可以转化成 cn.hutool.core.lang.func.VoidFunc1的Lambda表达式,和一个RuntimeException,当执行表达式抛出任何异常的时候,都会转化成运行时异常 * 如此一来,代码中就不用显示的try-catch转化成运行时异常 @@ -418,6 +290,7 @@ public class CheckedUtil { } public interface FuncRt extends Func { + @SuppressWarnings("unchecked") @Override R call(P... parameters) throws RuntimeException; } @@ -433,6 +306,7 @@ public class CheckedUtil { } public interface VoidFuncRt

extends VoidFunc

{ + @SuppressWarnings("unchecked") @Override void call(P... parameters) throws RuntimeException; } diff --git a/hutool-core/src/main/java/cn/hutool/core/net/SSLContextBuilder.java b/hutool-core/src/main/java/cn/hutool/core/net/SSLContextBuilder.java index d08c5fcdb..f7c783dc1 100644 --- a/hutool-core/src/main/java/cn/hutool/core/net/SSLContextBuilder.java +++ b/hutool-core/src/main/java/cn/hutool/core/net/SSLContextBuilder.java @@ -1,7 +1,6 @@ package cn.hutool.core.net; import cn.hutool.core.builder.Builder; -import cn.hutool.core.exceptions.CheckedUtil; import cn.hutool.core.io.IORuntimeException; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; @@ -29,7 +28,8 @@ import java.security.SecureRandom; * @since 5.5.2 */ public class SSLContextBuilder implements SSLProtocols, Builder { - + private static final long serialVersionUID = 1L; + private String protocol = TLS; private KeyManager[] keyManagers; private TrustManager[] trustManagers = {DefaultTrustManager.INSTANCE}; @@ -104,7 +104,7 @@ public class SSLContextBuilder implements SSLProtocols, Builder { */ @Override public SSLContext build() { - return CheckedUtil.uncheck(this::buildChecked, IORuntimeException::new).call(); + return buildQuietly(); } /** diff --git a/hutool-core/src/main/java/cn/hutool/core/net/SSLUtil.java b/hutool-core/src/main/java/cn/hutool/core/net/SSLUtil.java index 8519f94e0..d608467a0 100644 --- a/hutool-core/src/main/java/cn/hutool/core/net/SSLUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/net/SSLUtil.java @@ -23,7 +23,7 @@ public class SSLUtil { * @since 5.7.8 */ public static SSLContext createSSLContext(String protocol) throws IORuntimeException{ - return SSLContextBuilder.create().setProtocol(protocol).buildQuietly(); + return SSLContextBuilder.create().setProtocol(protocol).build(); } /** @@ -55,6 +55,6 @@ public class SSLUtil { return SSLContextBuilder.create() .setProtocol(protocol) .setKeyManagers(keyManagers) - .setTrustManagers(trustManagers).buildQuietly(); + .setTrustManagers(trustManagers).build(); } } diff --git a/hutool-core/src/test/java/cn/hutool/core/exceptions/CheckedUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/exceptions/CheckedUtilTest.java index 35be0f241..5790f24fa 100644 --- a/hutool-core/src/test/java/cn/hutool/core/exceptions/CheckedUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/exceptions/CheckedUtilTest.java @@ -38,7 +38,6 @@ public class CheckedUtilTest { } } - @SuppressWarnings("ConstantConditions") @Test public void functionTest() { Func1 afunc = (funcParam) -> { diff --git a/hutool-http/src/main/java/cn/hutool/http/ssl/SSLSocketFactoryBuilder.java b/hutool-http/src/main/java/cn/hutool/http/ssl/SSLSocketFactoryBuilder.java index bc94c8a1e..a52462e4a 100644 --- a/hutool-http/src/main/java/cn/hutool/http/ssl/SSLSocketFactoryBuilder.java +++ b/hutool-http/src/main/java/cn/hutool/http/ssl/SSLSocketFactoryBuilder.java @@ -90,6 +90,6 @@ public class SSLSocketFactoryBuilder implements SSLProtocols { * @throws KeyManagementException Key管理异常 */ public SSLSocketFactory build() throws NoSuchAlgorithmException, KeyManagementException { - return this.sslContextBuilder.build().getSocketFactory(); + return this.sslContextBuilder.buildChecked().getSocketFactory(); } }