@@ -886,17 +886,17 @@ public Size apply(
886
886
Label nextLabel = new Label ();
887
887
for ( int index = 0 ; index < setters .length ; index ++ ) {
888
888
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 ) {
890
894
methodVisitor .visitLabel ( currentLabel );
891
895
implementationContext .getFrameGeneration ().same (
892
896
methodVisitor ,
893
897
instrumentedMethod .getParameters ().asTypeList ()
894
898
);
895
899
}
896
- if ( setterMember == EMBEDDED_MEMBER ) {
897
- // The embedded property access does a no-op
898
- continue ;
899
- }
900
900
// Push entity on stack
901
901
methodVisitor .visitVarInsn ( Opcodes .ALOAD , 1 );
902
902
methodVisitor .visitTypeInsn ( Opcodes .CHECKCAST , Type .getInternalName ( clazz ) );
@@ -1023,6 +1023,7 @@ else if ( setterMember instanceof Field field ) {
1023
1023
}
1024
1024
if ( enhanced ) {
1025
1025
final boolean compositeTracker = CompositeTracker .class .isAssignableFrom ( type );
1026
+ boolean alreadyHasFrame = false ;
1026
1027
// The composite owner check and setting only makes sense if
1027
1028
// * the value type is a composite tracker
1028
1029
// * a value subtype can be a composite tracker
@@ -1104,6 +1105,7 @@ else if ( setterMember instanceof Field field ) {
1104
1105
// Clean stack after the if block
1105
1106
methodVisitor .visitLabel ( compositeTrackerEndLabel );
1106
1107
implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1108
+ alreadyHasFrame = true ;
1107
1109
}
1108
1110
if ( persistentAttributeInterceptable ) {
1109
1111
// Load the owner
@@ -1168,9 +1170,20 @@ else if ( setterMember instanceof Field field ) {
1168
1170
// Clean stack after the if block
1169
1171
methodVisitor .visitLabel ( instanceofEndLabel );
1170
1172
implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1173
+ alreadyHasFrame = true ;
1171
1174
}
1172
1175
1173
- currentLabel = nextLabel ;
1176
+ if ( alreadyHasFrame ) {
1177
+ // Usually, the currentLabel is visited as well generating a frame,
1178
+ // but if a frame was already generated, only visit the label here,
1179
+ // otherwise two frames for the same bytecode index are generated,
1180
+ // which is wrong and will produce an error when the JDK ClassFile API is used
1181
+ methodVisitor .visitLabel ( nextLabel );
1182
+ currentLabel = null ;
1183
+ }
1184
+ else {
1185
+ currentLabel = nextLabel ;
1186
+ }
1174
1187
nextLabel = new Label ();
1175
1188
}
1176
1189
}
0 commit comments