Merge branch 'v6-dev' of gitee.com:dromara/hutool into v6-dev

This commit is contained in:
Looly 2023-10-18 11:09:07 +08:00
commit 3ce8b1dc0b
3 changed files with 32 additions and 4 deletions

View File

@ -52,7 +52,11 @@ public class TypeUtil {
} else if (type instanceof ParameterizedType) {
return (Class<?>) ((ParameterizedType) type).getRawType();
} else if (type instanceof TypeVariable) {
return (Class<?>) ((TypeVariable<?>) type).getBounds()[0];
//return (Class<?>) ((TypeVariable<?>) type).getBounds()[0];
final Type[] bounds = ((TypeVariable<?>) type).getBounds();
if (bounds.length == 1) {
return getClass(bounds[0]);
}
} else if (type instanceof WildcardType) {
final Type[] upperBounds = ((WildcardType) type).getUpperBounds();
if (upperBounds.length == 1) {

View File

@ -82,6 +82,19 @@ public class TypeUtilTest {
Assertions.assertEquals(Long.class, idType);
}
@Test
public void getClasses() {
Method method = MethodUtil.getMethod(Parent.class, "getLevel");
Type returnType = TypeUtil.getReturnType(method);
Class<?> clazz = TypeUtil.getClass(returnType);
Assertions.assertEquals(Level1.class, clazz);
method = MethodUtil.getMethod(Level1.class, "getId");
returnType = TypeUtil.getReturnType(method);
clazz = TypeUtil.getClass(returnType);
Assertions.assertEquals(Object.class, clazz);
}
public static class Level3 extends Level2<Level3>{
}
@ -95,4 +108,9 @@ public class TypeUtilTest {
private T id;
}
@Data
public static class Parent<T extends Level1<B>, B extends Long> {
private T level;
}
}

View File

@ -12,6 +12,7 @@
package org.dromara.hutool.extra.aop.engine.spring;
import org.dromara.hutool.core.exception.ExceptionUtil;
import org.dromara.hutool.extra.aop.Aspect;
import org.dromara.hutool.extra.aop.SimpleInterceptor;
import org.springframework.cglib.proxy.MethodInterceptor;
@ -47,10 +48,15 @@ public class SpringCglibInterceptor extends SimpleInterceptor implements MethodI
if (aspect.before(target, method, args)) {
try {
result = proxy.invoke(target, args);
} catch (final InvocationTargetException e) {
} catch (final Throwable e) {
Throwable throwable = e;
if(throwable instanceof InvocationTargetException){
throwable = ((InvocationTargetException) throwable).getTargetException();
}
// 异常回调只捕获业务代码导致的异常而非反射导致的异常
if (aspect.afterException(target, method, args, e.getTargetException())) {
throw e;
if (aspect.afterException(target, method, args, throwable)) {
throw throwable;
}
}
}