Consistent handling of undeclared checked exceptions in CGLIB proxies (#32469)
Co-authored-by: hengyunabc <hengyunabc@gmail.com> Co-authored-by: Mikaël Francoeur <mikael.francoeur@ticketmaster.com>
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
|
||||
package org.springframework.cglib.core;
|
||||
|
||||
import java.lang.reflect.UndeclaredThrowableException;
|
||||
|
||||
import org.springframework.cglib.transform.impl.UndeclaredThrowableStrategy;
|
||||
|
||||
/**
|
||||
* CGLIB GeneratorStrategy variant which exposes the application ClassLoader
|
||||
* as current thread context ClassLoader for the time of class generation.
|
||||
@@ -25,11 +29,12 @@ package org.springframework.cglib.core;
|
||||
* @author Juergen Hoeller
|
||||
* @since 5.2
|
||||
*/
|
||||
public class ClassLoaderAwareGeneratorStrategy extends DefaultGeneratorStrategy {
|
||||
public class ClassLoaderAwareGeneratorStrategy extends UndeclaredThrowableStrategy {
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
public ClassLoaderAwareGeneratorStrategy(ClassLoader classLoader) {
|
||||
super(UndeclaredThrowableException.class);
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.springframework.cglib.core.Signature;
|
||||
import org.springframework.cglib.core.TypeUtils;
|
||||
import org.springframework.cglib.transform.ClassEmitterTransformer;
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@SuppressWarnings({"rawtypes" })
|
||||
public class UndeclaredThrowableTransformer extends ClassEmitterTransformer {
|
||||
|
||||
private final Type wrapper;
|
||||
@@ -55,10 +55,20 @@ public class UndeclaredThrowableTransformer extends ClassEmitterTransformer {
|
||||
return e;
|
||||
}
|
||||
return new CodeEmitter(e) {
|
||||
private Block handler;
|
||||
/* init */ {
|
||||
handler = begin_block();
|
||||
}
|
||||
private final boolean isConstructor = Constants.CONSTRUCTOR_NAME.equals(sig.getName());
|
||||
private Block handler = begin_block();
|
||||
private boolean calToSuperWasSeen;
|
||||
|
||||
@Override
|
||||
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
|
||||
super.visitMethodInsn(opcode, owner, name, descriptor, isInterface);
|
||||
if (isConstructor && !calToSuperWasSeen && Constants.CONSTRUCTOR_NAME.equals(name)) {
|
||||
// we start the entry in the exception table after the call to super
|
||||
handler = begin_block();
|
||||
calToSuperWasSeen = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMaxs(int maxStack, int maxLocals) {
|
||||
handler.end();
|
||||
|
||||
Reference in New Issue
Block a user