This commit is contained in:
Looly 2022-02-21 01:15:04 +08:00
parent 8251847d1f
commit 9151aa8968
6 changed files with 17 additions and 141 deletions

View File

@ -9,10 +9,13 @@
* 【extra 】 Ftp增加构造issue#I4TKXP@gitee
* 【core 】 GenericBuilder支持Map构建pr#540@Github
* 【json 】 新增TemporalAccessorSerializer
* 【core 】 使多个xxxBuilder实现Builder接口扩展CheckedUtilpr#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)

View File

@ -54,7 +54,7 @@ public class CheckedUtil {
* @return {@link FuncRt}
*/
public static <P, R> FuncRt<P, R> uncheck(Func<P, R> expression) {
return uncheck(expression, new RuntimeException());
return uncheck(expression, RuntimeException::new);
}
/**
@ -66,7 +66,7 @@ public class CheckedUtil {
* @return {@link Func0Rt}
*/
public static <R> Func0Rt<R> uncheck(Func0<R> expression) {
return uncheck(expression, new RuntimeException());
return uncheck(expression, RuntimeException::new);
}
/**
@ -79,7 +79,7 @@ public class CheckedUtil {
* @return {@link Func1Rt}
*/
public static <P, R> Func1Rt<P, R> uncheck(Func1<P, R> expression) {
return uncheck(expression, new RuntimeException());
return uncheck(expression, RuntimeException::new);
}
@ -92,7 +92,7 @@ public class CheckedUtil {
* @return {@link VoidFuncRt}
*/
public static <P> VoidFuncRt<P> uncheck(VoidFunc<P> 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 <P> VoidFunc1Rt<P> uncheck(VoidFunc1<P> 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 <P> 运行时传入的参数类型
* @param <R> 最终返回的数据类型
* @return {@link FuncRt}
*/
public static <P, R> FuncRt<P, R> uncheck(Func<P, R> 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 <R> 最终返回的数据类型
* @return {@link Func0Rt}
*/
public static <R> Func0Rt<R> uncheck(Func0<R> 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 <P> 运行时传入的参数类型
* @param <R> 最终返回的数据类型
* @return {@link Func1Rt}
*/
public static <P, R> Func1Rt<P, R> uncheck(Func1<P, R> 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 <P> 运行时传入的参数类型
* @return {@link VoidFuncRt}
*/
public static <P> VoidFuncRt<P> uncheck(VoidFunc<P> 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 <P> 运行时传入的参数类型
* @return {@link VoidFunc1Rt}
*/
public static <P> VoidFunc1Rt<P> uncheck(VoidFunc1<P> 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<P, R> extends Func<P, R> {
@SuppressWarnings("unchecked")
@Override
R call(P... parameters) throws RuntimeException;
}
@ -433,6 +306,7 @@ public class CheckedUtil {
}
public interface VoidFuncRt<P> extends VoidFunc<P> {
@SuppressWarnings("unchecked")
@Override
void call(P... parameters) throws RuntimeException;
}

View File

@ -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,6 +28,7 @@ import java.security.SecureRandom;
* @since 5.5.2
*/
public class SSLContextBuilder implements SSLProtocols, Builder<SSLContext> {
private static final long serialVersionUID = 1L;
private String protocol = TLS;
private KeyManager[] keyManagers;
@ -104,7 +104,7 @@ public class SSLContextBuilder implements SSLProtocols, Builder<SSLContext> {
*/
@Override
public SSLContext build() {
return CheckedUtil.uncheck(this::buildChecked, IORuntimeException::new).call();
return buildQuietly();
}
/**

View File

@ -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();
}
}

View File

@ -38,7 +38,6 @@ public class CheckedUtilTest {
}
}
@SuppressWarnings("ConstantConditions")
@Test
public void functionTest() {
Func1<String, String> afunc = (funcParam) -> {

View File

@ -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();
}
}