Merge branch '6.2.x'
This commit is contained in:
commit
acc3783509
|
@ -19,6 +19,7 @@ package org.springframework.aop.framework
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for Kotlin support in [CglibAopProxy].
|
* Tests for Kotlin support in [CglibAopProxy].
|
||||||
|
@ -48,6 +49,13 @@ class CglibAopProxyKotlinTests {
|
||||||
assertThatThrownBy { proxy.checkedException() }.isInstanceOf(CheckedException::class.java)
|
assertThatThrownBy { proxy.checkedException() }.isInstanceOf(CheckedException::class.java)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // gh-35487
|
||||||
|
fun jvmDefault() {
|
||||||
|
val proxyFactory = ProxyFactory()
|
||||||
|
proxyFactory.setTarget(AddressRepo())
|
||||||
|
proxyFactory.proxy
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
open class MyKotlinBean {
|
open class MyKotlinBean {
|
||||||
|
|
||||||
|
@ -63,4 +71,24 @@ class CglibAopProxyKotlinTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
class CheckedException() : Exception()
|
class CheckedException() : Exception()
|
||||||
|
|
||||||
|
open class AddressRepo(): CrudRepo<Address, Int>
|
||||||
|
|
||||||
|
interface CrudRepo<E : Any, ID : Any> {
|
||||||
|
fun save(e: E): E {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
fun delete(id: ID): Long {
|
||||||
|
return 0L
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Address(
|
||||||
|
val id: Int = 0,
|
||||||
|
val street: String,
|
||||||
|
val version: Int = 0,
|
||||||
|
val createdAt: LocalDateTime? = null,
|
||||||
|
val updatedAt: LocalDateTime? = null,
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1282,29 +1282,32 @@ public class Enhancer extends AbstractClassGenerator {
|
||||||
Signature bridgeTarget = (Signature) bridgeToTarget.get(method.getSignature());
|
Signature bridgeTarget = (Signature) bridgeToTarget.get(method.getSignature());
|
||||||
if (bridgeTarget != null) {
|
if (bridgeTarget != null) {
|
||||||
// checkcast each argument against the target's argument types
|
// checkcast each argument against the target's argument types
|
||||||
for (int i = 0; i < bridgeTarget.getArgumentTypes().length; i++) {
|
Type[] argTypes = method.getSignature().getArgumentTypes();
|
||||||
|
Type[] targetTypes = bridgeTarget.getArgumentTypes();
|
||||||
|
for (int i = 0; i < targetTypes.length; i++) {
|
||||||
e.load_arg(i);
|
e.load_arg(i);
|
||||||
Type target = bridgeTarget.getArgumentTypes()[i];
|
Type argType = argTypes[i];
|
||||||
if (!target.equals(method.getSignature().getArgumentTypes()[i])) {
|
Type target = targetTypes[i];
|
||||||
|
if (!target.equals(argType)) {
|
||||||
|
if (!TypeUtils.isPrimitive(target)) {
|
||||||
|
e.box(argType);
|
||||||
|
}
|
||||||
e.checkcast(target);
|
e.checkcast(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
e.invoke_virtual_this(bridgeTarget);
|
e.invoke_virtual_this(bridgeTarget);
|
||||||
|
|
||||||
|
// Not necessary to cast if the target & bridge have the same return type.
|
||||||
Type retType = method.getSignature().getReturnType();
|
Type retType = method.getSignature().getReturnType();
|
||||||
// Not necessary to cast if the target & bridge have
|
Type target = bridgeTarget.getReturnType();
|
||||||
// the same return type.
|
if (!target.equals(retType)) {
|
||||||
// (This conveniently includes void and primitive types,
|
if (!TypeUtils.isPrimitive(target)) {
|
||||||
// which would fail if casted. It's not possible to
|
e.unbox(retType);
|
||||||
// covariant from boxed to unbox (or vice versa), so no having
|
}
|
||||||
// to box/unbox for bridges).
|
else {
|
||||||
// TODO: It also isn't necessary to checkcast if the return is
|
e.checkcast(retType);
|
||||||
// assignable from the target. (This would happen if a subclass
|
}
|
||||||
// used covariant returns to narrow the return type within a bridge
|
|
||||||
// method.)
|
|
||||||
if (!retType.equals(bridgeTarget.getReturnType())) {
|
|
||||||
e.checkcast(retType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in New Issue