@@ -833,17 +833,17 @@ public Size apply(
833
833
Label nextLabel = new Label ();
834
834
for ( int index = 0 ; index < setters .length ; index ++ ) {
835
835
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 ) {
837
841
methodVisitor .visitLabel ( currentLabel );
838
842
implementationContext .getFrameGeneration ().same (
839
843
methodVisitor ,
840
844
instrumentedMethod .getParameters ().asTypeList ()
841
845
);
842
846
}
843
- if ( setterMember == EMBEDDED_MEMBER ) {
844
- // The embedded property access does a no-op
845
- continue ;
846
- }
847
847
// Push entity on stack
848
848
methodVisitor .visitVarInsn ( Opcodes .ALOAD , 1 );
849
849
methodVisitor .visitTypeInsn ( Opcodes .CHECKCAST , Type .getInternalName ( clazz ) );
@@ -975,6 +975,7 @@ else if ( setterMember instanceof Field ) {
975
975
}
976
976
if ( enhanced ) {
977
977
final boolean compositeTracker = CompositeTracker .class .isAssignableFrom ( type );
978
+ boolean alreadyHasFrame = false ;
978
979
// The composite owner check and setting only makes sense if
979
980
// * the value type is a composite tracker
980
981
// * a value subtype can be a composite tracker
@@ -1056,6 +1057,7 @@ else if ( setterMember instanceof Field ) {
1056
1057
// Clean stack after the if block
1057
1058
methodVisitor .visitLabel ( compositeTrackerEndLabel );
1058
1059
implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1060
+ alreadyHasFrame = true ;
1059
1061
}
1060
1062
if ( persistentAttributeInterceptable ) {
1061
1063
// Load the owner
@@ -1120,9 +1122,20 @@ else if ( setterMember instanceof Field ) {
1120
1122
// Clean stack after the if block
1121
1123
methodVisitor .visitLabel ( instanceofEndLabel );
1122
1124
implementationContext .getFrameGeneration ().same (methodVisitor , instrumentedMethod .getParameters ().asTypeList ());
1125
+ alreadyHasFrame = true ;
1123
1126
}
1124
1127
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
+ }
1126
1139
nextLabel = new Label ();
1127
1140
}
1128
1141
}
0 commit comments