@@ -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 ) );
@@ -1023,6 +1023,7 @@ else if ( setterMember instanceof Field field ) {
10231023 }
10241024 if ( enhanced ) {
10251025 final boolean compositeTracker = CompositeTracker .class .isAssignableFrom ( type );
1026+ boolean alreadyHasFrame = false ;
10261027 // The composite owner check and setting only makes sense if
10271028 // * the value type is a composite tracker
10281029 // * a value subtype can be a composite tracker
@@ -1104,6 +1105,7 @@ else if ( setterMember instanceof Field field ) {
11041105 // Clean stack after the if block
11051106 methodVisitor .visitLabel ( compositeTrackerEndLabel );
11061107 implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1108+ alreadyHasFrame = true ;
11071109 }
11081110 if ( persistentAttributeInterceptable ) {
11091111 // Load the owner
@@ -1168,9 +1170,20 @@ else if ( setterMember instanceof Field field ) {
11681170 // Clean stack after the if block
11691171 methodVisitor .visitLabel ( instanceofEndLabel );
11701172 implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1173+ alreadyHasFrame = true ;
11711174 }
11721175
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+ }
11741187 nextLabel = new Label ();
11751188 }
11761189 }
0 commit comments