From 5189fa52dd22367a4119a9ef7cce12501e69ebd9 Mon Sep 17 00:00:00 2001 From: xudeping Date: Fri, 14 Oct 2022 17:33:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:ReflectUtil.invokeRaw=20=20=E5=AF=B9?= =?UTF-8?q?=E4=BA=8E=E7=B1=BB=E5=9E=8B=E4=B8=8D=E5=90=8C=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E5=B0=9D=E8=AF=95=E8=BD=AC=E6=8D=A2=EF=BC=8C?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E5=A4=B1=E8=B4=A5=E5=88=99=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=8E=9F=E5=AF=B9=E8=B1=A1=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/cn/hutool/core/util/ReflectUtil.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java b/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java index a94a5007f..3af14a44e 100755 --- a/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/util/ReflectUtil.java @@ -327,7 +327,7 @@ public class ReflectUtil { * * @param obj 对象,如果是static字段,此参数为null * @param field 字段 - * @param value 值,当值类型与字段类型不匹配时,会尝试转换 + * @param value 值,当值类型与字段类型不匹配时,会尝试转换 * @throws UtilException UtilException 包装IllegalAccessException异常 */ public static void setFieldValue(Object obj, Field field, Object value) throws UtilException { @@ -544,10 +544,10 @@ public class ReflectUtil { if (ArrayUtil.isNotEmpty(methods)) { for (Method method : methods) { if (StrUtil.equals(methodName, method.getName(), ignoreCase) - && ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes) - //排除协变桥接方法,pr#1965@Github - && (res == null - || res.getReturnType().isAssignableFrom(method.getReturnType()))) { + && ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes) + //排除协变桥接方法,pr#1965@Github + && (res == null + || res.getReturnType().isAssignableFrom(method.getReturnType()))) { res = method; } } @@ -613,9 +613,9 @@ public class ReflectUtil { if (ArrayUtil.isNotEmpty(methods)) { for (Method method : methods) { if (StrUtil.equals(methodName, method.getName(), ignoreCase) - //排除协变桥接方法,pr#1965@Github - && (res == null - || res.getReturnType().isAssignableFrom(method.getReturnType()))) { + //排除协变桥接方法,pr#1965@Github + && (res == null + || res.getReturnType().isAssignableFrom(method.getReturnType()))) { res = method; } } @@ -665,7 +665,7 @@ public class ReflectUtil { public static Method[] getMethods(Class beanClass) throws SecurityException { Assert.notNull(beanClass); return METHODS_CACHE.computeIfAbsent(beanClass, - () -> getMethodsDirectly(beanClass, true, true)); + () -> getMethodsDirectly(beanClass, true, true)); } /** @@ -715,8 +715,8 @@ public class ReflectUtil { */ public static boolean isEqualsMethod(Method method) { if (method == null || - 1 != method.getParameterCount() || - false == "equals".equals(method.getName())) { + 1 != method.getParameterCount() || + false == "equals".equals(method.getName())) { return false; } return (method.getParameterTypes()[0] == Object.class); @@ -730,8 +730,8 @@ public class ReflectUtil { */ public static boolean isHashCodeMethod(Method method) { return method != null// - && "hashCode".equals(method.getName())// - && isEmptyParam(method); + && "hashCode".equals(method.getName())// + && isEmptyParam(method); } /** @@ -742,8 +742,8 @@ public class ReflectUtil { */ public static boolean isToStringMethod(Method method) { return method != null// - && "toString".equals(method.getName())// - && isEmptyParam(method); + && "toString".equals(method.getName())// + && isEmptyParam(method); } /** @@ -846,7 +846,7 @@ public class ReflectUtil { public static T newInstance(Class clazz, Object... params) throws UtilException { if (ArrayUtil.isEmpty(params)) { final Constructor constructor = getConstructor(clazz); - if(null == constructor){ + if (null == constructor) { throw new UtilException("No constructor for [{}]", clazz); } try { @@ -1056,7 +1056,7 @@ public class ReflectUtil { actualArgs[i] = null; } else if (false == parameterTypes[i].isAssignableFrom(args[i].getClass())) { //对于类型不同的字段,尝试转换,转换失败则使用原对象类型 - final Object targetValue = Convert.convert(parameterTypes[i], args[i]); + final Object targetValue = Convert.convertQuietly(parameterTypes[i], args[i], args[i]); if (null != targetValue) { actualArgs[i] = targetValue; }