mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复ReflectUtil 反射方法中桥接问题
This commit is contained in:
parent
e59548ebbf
commit
8d348b539d
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.8.8.M1 (2022-09-22)
|
# 5.8.8.M1 (2022-09-23)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【core 】 StreamUtil.of方法新增对 Iterator 支持;StreamUtil.of(Iterable) 方法优化(pr#807@Gitee)
|
* 【core 】 StreamUtil.of方法新增对 Iterator 支持;StreamUtil.of(Iterable) 方法优化(pr#807@Gitee)
|
||||||
@ -17,6 +17,7 @@
|
|||||||
* 【core 】 修复murmur3_32实现错误(pr#2616@Github)
|
* 【core 】 修复murmur3_32实现错误(pr#2616@Github)
|
||||||
* 【core 】 修复PunyCode处理域名的问题(pr#2620@Github)
|
* 【core 】 修复PunyCode处理域名的问题(pr#2620@Github)
|
||||||
* 【core 】 修复ObjectUtil.defaultIfNull去掉误加的deprecated(issue#I5SIZT@Gitee)
|
* 【core 】 修复ObjectUtil.defaultIfNull去掉误加的deprecated(issue#I5SIZT@Gitee)
|
||||||
|
* 【core 】 修复ReflectUtil 反射方法中桥接判断问题(issue#2625@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -539,18 +539,20 @@ public class ReflectUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Method res = null;
|
||||||
final Method[] methods = getMethods(clazz);
|
final Method[] methods = getMethods(clazz);
|
||||||
if (ArrayUtil.isNotEmpty(methods)) {
|
if (ArrayUtil.isNotEmpty(methods)) {
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (StrUtil.equals(methodName, method.getName(), ignoreCase)
|
if (StrUtil.equals(methodName, method.getName(), ignoreCase)
|
||||||
&& ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes)
|
&& ClassUtil.isAllAssignableFrom(method.getParameterTypes(), paramTypes)
|
||||||
//排除桥接方法,pr#1965@Github
|
//排除协变桥接方法,pr#1965@Github
|
||||||
&& false == method.isBridge()) {
|
&& (res == null
|
||||||
return method;
|
|| res.getReturnType().isAssignableFrom(method.getReturnType()))) {
|
||||||
|
res = method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -606,17 +608,19 @@ public class ReflectUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Method res = null;
|
||||||
final Method[] methods = getMethods(clazz);
|
final Method[] methods = getMethods(clazz);
|
||||||
if (ArrayUtil.isNotEmpty(methods)) {
|
if (ArrayUtil.isNotEmpty(methods)) {
|
||||||
for (Method method : methods) {
|
for (Method method : methods) {
|
||||||
if (StrUtil.equals(methodName, method.getName(), ignoreCase)
|
if (StrUtil.equals(methodName, method.getName(), ignoreCase)
|
||||||
// 排除桥接方法
|
//排除协变桥接方法,pr#1965@Github
|
||||||
&& false == method.isBridge()) {
|
&& (res == null
|
||||||
return method;
|
|| res.getReturnType().isAssignableFrom(method.getReturnType()))) {
|
||||||
|
res = method;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -292,4 +292,25 @@ public class ReflectUtilTest {
|
|||||||
|
|
||||||
Assert.assertEquals(dialects, ReflectUtil.getFieldValue(JdbcDialects.class, fieldName));
|
Assert.assertEquals(dialects, ReflectUtil.getFieldValue(JdbcDialects.class, fieldName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void issue2625Test(){
|
||||||
|
// 内部类继承的情况下父类方法会被定义为桥接方法,因此按照pr#1965@Github判断返回值的继承关系来代替判断桥接。
|
||||||
|
final Method getThis = ReflectUtil.getMethod(A.C.class, "getThis");
|
||||||
|
Assert.assertTrue(getThis.isBridge());
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("InnerClassMayBeStatic")
|
||||||
|
public class A{
|
||||||
|
|
||||||
|
public class C extends B{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected class B{
|
||||||
|
public B getThis(){
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user