Skip to content

Commit 56adc8b

Browse files
committed
HHH-19577 Avoid duplicate stack map frames for SetPropertyValues
1 parent 3b19d79 commit 56adc8b

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

hibernate-core/src/main/java/org/hibernate/bytecode/internal/bytebuddy/BytecodeProviderImpl.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -886,17 +886,17 @@ public Size apply(
886886
Label nextLabel = new Label();
887887
for ( int index = 0; index < setters.length; index++ ) {
888888
final Member setterMember = setters[index];
889-
if ( enhanced && currentLabel != null ) {
889+
if ( setterMember == EMBEDDED_MEMBER ) {
890+
// The embedded property access does a no-op
891+
continue;
892+
}
893+
if ( currentLabel != null ) {
890894
methodVisitor.visitLabel( currentLabel );
891895
implementationContext.getFrameGeneration().same(
892896
methodVisitor,
893897
instrumentedMethod.getParameters().asTypeList()
894898
);
895899
}
896-
if ( setterMember == EMBEDDED_MEMBER ) {
897-
// The embedded property access does a no-op
898-
continue;
899-
}
900900
// Push entity on stack
901901
methodVisitor.visitVarInsn( Opcodes.ALOAD, 1 );
902902
methodVisitor.visitTypeInsn( Opcodes.CHECKCAST, Type.getInternalName( clazz ) );
@@ -1028,6 +1028,7 @@ else if ( setterMember instanceof Field ) {
10281028
}
10291029
if ( enhanced ) {
10301030
final boolean compositeTracker = CompositeTracker.class.isAssignableFrom( type );
1031+
boolean alreadyHasFrame = false;
10311032
// The composite owner check and setting only makes sense if
10321033
// * the value type is a composite tracker
10331034
// * a value subtype can be a composite tracker
@@ -1109,6 +1110,7 @@ else if ( setterMember instanceof Field ) {
11091110
// Clean stack after the if block
11101111
methodVisitor.visitLabel( compositeTrackerEndLabel );
11111112
implementationContext.getFrameGeneration().same(methodVisitor, instrumentedMethod.getParameters().asTypeList());
1113+
alreadyHasFrame = true;
11121114
}
11131115
if ( persistentAttributeInterceptable ) {
11141116
// Load the owner
@@ -1173,9 +1175,20 @@ else if ( setterMember instanceof Field ) {
11731175
// Clean stack after the if block
11741176
methodVisitor.visitLabel( instanceofEndLabel );
11751177
implementationContext.getFrameGeneration().same(methodVisitor, instrumentedMethod.getParameters().asTypeList());
1178+
alreadyHasFrame = true;
11761179
}
11771180

1178-
currentLabel = nextLabel;
1181+
if ( alreadyHasFrame ) {
1182+
// Usually, the currentLabel is visited as well generating a frame,
1183+
// but if a frame was already generated, only visit the label here,
1184+
// otherwise two frames for the same bytecode index are generated,
1185+
// which is wrong and will produce an error when the JDK ClassFile API is used
1186+
methodVisitor.visitLabel( nextLabel );
1187+
currentLabel = null;
1188+
}
1189+
else {
1190+
currentLabel = nextLabel;
1191+
}
11791192
nextLabel = new Label();
11801193
}
11811194
}

0 commit comments

Comments
 (0)