@@ -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 ) );
@@ -1028,6 +1028,7 @@ else if ( setterMember instanceof Field ) {
1028
1028
}
1029
1029
if ( enhanced ) {
1030
1030
final boolean compositeTracker = CompositeTracker .class .isAssignableFrom ( type );
1031
+ boolean alreadyHasFrame = false ;
1031
1032
// The composite owner check and setting only makes sense if
1032
1033
// * the value type is a composite tracker
1033
1034
// * a value subtype can be a composite tracker
@@ -1109,6 +1110,7 @@ else if ( setterMember instanceof Field ) {
1109
1110
// Clean stack after the if block
1110
1111
methodVisitor .visitLabel ( compositeTrackerEndLabel );
1111
1112
implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1113
+ alreadyHasFrame = true ;
1112
1114
}
1113
1115
if ( persistentAttributeInterceptable ) {
1114
1116
// Load the owner
@@ -1173,9 +1175,20 @@ else if ( setterMember instanceof Field ) {
1173
1175
// Clean stack after the if block
1174
1176
methodVisitor .visitLabel ( instanceofEndLabel );
1175
1177
implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1178
+ alreadyHasFrame = true ;
1176
1179
}
1177
1180
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
+ }
1179
1192
nextLabel = new Label ();
1180
1193
}
1181
1194
}
0 commit comments