@@ -833,17 +833,17 @@ public Size apply(
833833 Label nextLabel = new Label ();
834834 for ( int index = 0 ; index < setters .length ; index ++ ) {
835835 final Member setterMember = setters [index ];
836- if ( enhanced && currentLabel != null ) {
836+ if ( setterMember == EMBEDDED_MEMBER ) {
837+ // The embedded property access does a no-op
838+ continue ;
839+ }
840+ if ( currentLabel != null ) {
837841 methodVisitor .visitLabel ( currentLabel );
838842 implementationContext .getFrameGeneration ().same (
839843 methodVisitor ,
840844 instrumentedMethod .getParameters ().asTypeList ()
841845 );
842846 }
843- if ( setterMember == EMBEDDED_MEMBER ) {
844- // The embedded property access does a no-op
845- continue ;
846- }
847847 // Push entity on stack
848848 methodVisitor .visitVarInsn ( Opcodes .ALOAD , 1 );
849849 methodVisitor .visitTypeInsn ( Opcodes .CHECKCAST , Type .getInternalName ( clazz ) );
@@ -975,6 +975,7 @@ else if ( setterMember instanceof Field ) {
975975 }
976976 if ( enhanced ) {
977977 final boolean compositeTracker = CompositeTracker .class .isAssignableFrom ( type );
978+ boolean alreadyHasFrame = false ;
978979 // The composite owner check and setting only makes sense if
979980 // * the value type is a composite tracker
980981 // * a value subtype can be a composite tracker
@@ -1056,6 +1057,7 @@ else if ( setterMember instanceof Field ) {
10561057 // Clean stack after the if block
10571058 methodVisitor .visitLabel ( compositeTrackerEndLabel );
10581059 implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1060+ alreadyHasFrame = true ;
10591061 }
10601062 if ( persistentAttributeInterceptable ) {
10611063 // Load the owner
@@ -1120,9 +1122,20 @@ else if ( setterMember instanceof Field ) {
11201122 // Clean stack after the if block
11211123 methodVisitor .visitLabel ( instanceofEndLabel );
11221124 implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1125+ alreadyHasFrame = true ;
11231126 }
11241127
1125- currentLabel = nextLabel ;
1128+ if ( alreadyHasFrame ) {
1129+ // Usually, the currentLabel is visited as well generating a frame,
1130+ // but if a frame was already generated, only visit the label here,
1131+ // otherwise two frames for the same bytecode index are generated,
1132+ // which is wrong and will produce an error when the JDK ClassFile API is used
1133+ methodVisitor .visitLabel ( nextLabel );
1134+ currentLabel = null ;
1135+ }
1136+ else {
1137+ currentLabel = nextLabel ;
1138+ }
11261139 nextLabel = new Label ();
11271140 }
11281141 }
0 commit comments