Skip to content

Commit 3e37279

Browse files
jhoellersdeleuze
authored andcommitted
Make CGLIB Enhancer compatible with Kotlin 2.2.20+
This commit refines Enhancer#emitMethods to support the changes introduced by https://youtrack.jetbrains.com/issue/KT-76667. See gh-35487
1 parent b3264ec commit 3e37279

File tree

1 file changed

+18
-15
lines changed
  • spring-core/src/main/java/org/springframework/cglib/proxy

1 file changed

+18
-15
lines changed

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
@@ -1278,29 +1278,32 @@ public void emitLoadArgsAndInvoke(CodeEmitter e, MethodInfo method) {
12781278
Signature bridgeTarget = (Signature) bridgeToTarget.get(method.getSignature());
12791279
if (bridgeTarget != null) {
12801280
// checkcast each argument against the target's argument types
1281-
for (int i = 0; i < bridgeTarget.getArgumentTypes().length; i++) {
1281+
Type[] argTypes = method.getSignature().getArgumentTypes();
1282+
Type[] targetTypes = bridgeTarget.getArgumentTypes();
1283+
for (int i = 0; i < targetTypes.length; i++) {
12821284
e.load_arg(i);
1283-
Type target = bridgeTarget.getArgumentTypes()[i];
1284-
if (!target.equals(method.getSignature().getArgumentTypes()[i])) {
1285+
Type argType = argTypes[i];
1286+
Type target = targetTypes[i];
1287+
if (!target.equals(argType)) {
1288+
if (!TypeUtils.isPrimitive(target)) {
1289+
e.box(argType);
1290+
}
12851291
e.checkcast(target);
12861292
}
12871293
}
12881294

12891295
e.invoke_virtual_this(bridgeTarget);
12901296

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

0 commit comments

Comments
 (0)