mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
!1103 fix 修复合成注解会无限递归获取映射属性的问题 Gitee#I8CLBJ
Merge pull request !1103 from Createsequence/fix-I8CLBJ
This commit is contained in:
commit
a21f202ec6
@ -95,12 +95,13 @@ public class SynthesizedAnnotationProxy implements InvocationHandler {
|
|||||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||||
return Opt.ofNullable(methods.get(method.getName()))
|
return Opt.ofNullable(methods.get(method.getName()))
|
||||||
.map(m -> m.apply(method, args))
|
.map(m -> m.apply(method, args))
|
||||||
.orElseGet(() -> ReflectUtil.invoke(proxy, method, args));
|
.orElseGet(() -> ReflectUtil.invoke(annotation.getAnnotation(), method, args));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================= 代理方法 =========================
|
// ========================= 代理方法 =========================
|
||||||
|
|
||||||
void loadMethods() {
|
void loadMethods() {
|
||||||
|
// 非用户属性
|
||||||
methods.put("toString", (method, args) -> proxyToString());
|
methods.put("toString", (method, args) -> proxyToString());
|
||||||
methods.put("hashCode", (method, args) -> proxyHashCode());
|
methods.put("hashCode", (method, args) -> proxyHashCode());
|
||||||
methods.put("getSynthesizedAnnotation", (method, args) -> proxyGetSynthesizedAnnotation());
|
methods.put("getSynthesizedAnnotation", (method, args) -> proxyGetSynthesizedAnnotation());
|
||||||
@ -114,9 +115,11 @@ public class SynthesizedAnnotationProxy implements InvocationHandler {
|
|||||||
});
|
});
|
||||||
methods.put("getAttributeValue", (method, args) -> annotation.getAttributeValue((String) args[0]));
|
methods.put("getAttributeValue", (method, args) -> annotation.getAttributeValue((String) args[0]));
|
||||||
methods.put("annotationType", (method, args) -> annotation.annotationType());
|
methods.put("annotationType", (method, args) -> annotation.annotationType());
|
||||||
for (final Method declaredMethod : ClassUtil.getDeclaredMethods(annotation.getAnnotation().annotationType())) {
|
|
||||||
methods.put(declaredMethod.getName(), (method, args) -> proxyAttributeValue(method));
|
// 可以被合成的用户属性
|
||||||
}
|
Stream.of(ClassUtil.getDeclaredMethods(annotation.getAnnotation().annotationType()))
|
||||||
|
.filter(m -> !methods.containsKey(m.getName()))
|
||||||
|
.forEach(m -> methods.put(m.getName(), (method, args) -> proxyAttributeValue(method)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String proxyToString() {
|
private String proxyToString() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user