1616import java .util .Collections ;
1717import java .util .List ;
1818import java .util .Map ;
19- import java .util .concurrent .Callable ;
2019
2120import org .hibernate .AssertionFailure ;
2221import org .hibernate .HibernateException ;
@@ -183,7 +182,7 @@ public ReflectionOptimizer getReflectionOptimizer(
183182 .method ( setPropertyValuesMethodName )
184183 .intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , getterNames , setters ) ) )
185184 .method ( getPropertyNamesMethodName )
186- .intercept ( MethodCall . call ( new CloningPropertyCall ( getterNames ) ) )
185+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( getterNames ) ) )
187186 );
188187
189188 try {
@@ -252,7 +251,7 @@ public ReflectionOptimizer getReflectionOptimizer(
252251 .method ( setPropertyValuesMethodName )
253252 .intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , propertyNames , setters ) ) )
254253 .method ( getPropertyNamesMethodName )
255- .intercept ( MethodCall . call ( new CloningPropertyCall ( propertyNames ) ) )
254+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( propertyNames ) ) )
256255 );
257256 }
258257 else {
@@ -265,7 +264,7 @@ public ReflectionOptimizer getReflectionOptimizer(
265264 .method ( setPropertyValuesMethodName )
266265 .intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , propertyNames , setters ) ) )
267266 .method ( getPropertyNamesMethodName )
268- .intercept ( MethodCall . call ( new CloningPropertyCall ( propertyNames ) ) )
267+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( propertyNames ) ) )
269268 );
270269 }
271270
@@ -1341,17 +1340,29 @@ private static Constructor<?> findConstructor(Class<?> clazz) {
13411340 }
13421341 }
13431342
1344- public static class CloningPropertyCall implements Callable < String []> {
1343+ public static class GetPropertyNames implements ByteCodeAppender {
13451344
13461345 private final String [] propertyNames ;
13471346
1348- private CloningPropertyCall (String [] propertyNames ) {
1347+ private GetPropertyNames (String [] propertyNames ) {
13491348 this .propertyNames = propertyNames ;
13501349 }
13511350
13521351 @ Override
1353- public String [] call () {
1354- return propertyNames .clone ();
1352+ public Size apply (
1353+ MethodVisitor methodVisitor ,
1354+ Implementation .Context implementationContext ,
1355+ MethodDescription instrumentedMethod ) {
1356+ methodVisitor .visitLdcInsn ( propertyNames .length );
1357+ methodVisitor .visitTypeInsn ( Opcodes .ANEWARRAY , Type .getInternalName ( String .class ) );
1358+ for ( int i = 0 ; i < propertyNames .length ; i ++ ) {
1359+ methodVisitor .visitInsn ( Opcodes .DUP );
1360+ methodVisitor .visitLdcInsn ( i );
1361+ methodVisitor .visitLdcInsn ( propertyNames [i ] );
1362+ methodVisitor .visitInsn ( Opcodes .AASTORE );
1363+ }
1364+ methodVisitor .visitInsn ( Opcodes .ARETURN );
1365+ return new Size ( 4 , instrumentedMethod .getStackSize () + 1 );
13551366 }
13561367 }
13571368
0 commit comments