Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit acc3783

Browse files
committed
Merge branch '6.2.x'
2 parents c765b03 + cb849a7 commit acc3783

File tree

2 files changed

+46
-15
lines changed

2 files changed

+46
-15
lines changed

‎spring-aop/src/test/kotlin/org/springframework/aop/framework/CglibAopProxyKotlinTests.kt‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.springframework.aop.framework
1919
import org.assertj.core.api.Assertions.assertThat
2020
import org.assertj.core.api.Assertions.assertThatThrownBy
2121
import org.junit.jupiter.api.Test
22+
import java.time.LocalDateTime
2223

2324
/**
2425
* Tests for Kotlin support in [CglibAopProxy].
@@ -48,6 +49,13 @@ class CglibAopProxyKotlinTests {
4849
assertThatThrownBy { proxy.checkedException() }.isInstanceOf(CheckedException::class.java)
4950
}
5051

52+
@Test // gh-35487
53+
fun jvmDefault() {
54+
val proxyFactory = ProxyFactory()
55+
proxyFactory.setTarget(AddressRepo())
56+
proxyFactory.proxy
57+
}
58+
5159

5260
open class MyKotlinBean {
5361

@@ -63,4 +71,24 @@ class CglibAopProxyKotlinTests {
6371
}
6472

6573
class CheckedException() : Exception()
74+
75+
open class AddressRepo(): CrudRepo<Address, Int>
76+
77+
interface CrudRepo<E : Any, ID : Any> {
78+
fun save(e: E): E {
79+
return e
80+
}
81+
fun delete(id: ID): Long {
82+
return 0L
83+
}
84+
}
85+
86+
data class Address(
87+
val id: Int = 0,
88+
val street: String,
89+
val version: Int = 0,
90+
val createdAt: LocalDateTime? = null,
91+
val updatedAt: LocalDateTime? = null,
92+
)
93+
6694
}

‎spring-core/src/main/java/org/springframework/cglib/proxy/Enhancer.java‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,29 +1282,32 @@ public void emitLoadArgsAndInvoke(CodeEmitter e, MethodInfo method) {
12821282
Signature bridgeTarget = (Signature) bridgeToTarget.get(method.getSignature());
12831283
if (bridgeTarget != null) {
12841284
// checkcast each argument against the target's argument types
1285-
for (int i = 0; i < bridgeTarget.getArgumentTypes().length; i++) {
1285+
Type[] argTypes = method.getSignature().getArgumentTypes();
1286+
Type[] targetTypes = bridgeTarget.getArgumentTypes();
1287+
for (int i = 0; i < targetTypes.length; i++) {
12861288
e.load_arg(i);
1287-
Type target = bridgeTarget.getArgumentTypes()[i];
1288-
if (!target.equals(method.getSignature().getArgumentTypes()[i])) {
1289+
Type argType = argTypes[i];
1290+
Type target = targetTypes[i];
1291+
if (!target.equals(argType)) {
1292+
if (!TypeUtils.isPrimitive(target)) {
1293+
e.box(argType);
1294+
}
12891295
e.checkcast(target);
12901296
}
12911297
}
12921298

12931299
e.invoke_virtual_this(bridgeTarget);
12941300

1301+
// Not necessary to cast if the target & bridge have the same return type.
12951302
Type retType = method.getSignature().getReturnType();
1296-
// Not necessary to cast if the target & bridge have
1297-
// the same return type.
1298-
// (This conveniently includes void and primitive types,
1299-
// which would fail if casted. It's not possible to
1300-
// covariant from boxed to unbox (or vice versa), so no having
1301-
// to box/unbox for bridges).
1302-
// TODO: It also isn't necessary to checkcast if the return is
1303-
// assignable from the target. (This would happen if a subclass
1304-
// used covariant returns to narrow the return type within a bridge
1305-
// method.)
1306-
if (!retType.equals(bridgeTarget.getReturnType())) {
1307-
e.checkcast(retType);
1303+
Type target = bridgeTarget.getReturnType();
1304+
if (!target.equals(retType)) {
1305+
if (!TypeUtils.isPrimitive(target)) {
1306+
e.unbox(retType);
1307+
}
1308+
else {
1309+
e.checkcast(retType);
1310+
}
13081311
}
13091312
}
13101313
else {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /