1818import java .util .Collections ;
1919import java .util .List ;
2020import java .util .Map ;
21- import java .util .concurrent .Callable ;
2221
2322import org .hibernate .HibernateException ;
2423import org .hibernate .bytecode .enhance .internal .bytebuddy .EnhancerClassLocator ;
@@ -184,7 +183,7 @@ public ReflectionOptimizer getReflectionOptimizer(
184183 .method ( setPropertyValuesMethodName )
185184 .intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , getterNames , setters ) ) )
186185 .method ( getPropertyNamesMethodName )
187- .intercept ( MethodCall . call ( new CloningPropertyCall ( getterNames ) ) )
186+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( getterNames ) ) )
188187 );
189188
190189 try {
@@ -253,7 +252,7 @@ public ReflectionOptimizer getReflectionOptimizer(
253252 .method ( setPropertyValuesMethodName )
254253 .intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , propertyNames , setters ) ) )
255254 .method ( getPropertyNamesMethodName )
256- .intercept ( MethodCall . call ( new CloningPropertyCall ( propertyNames ) ) )
255+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( propertyNames ) ) )
257256 );
258257 }
259258 else {
@@ -266,7 +265,7 @@ public ReflectionOptimizer getReflectionOptimizer(
266265 .method ( setPropertyValuesMethodName )
267266 .intercept ( new Implementation .Simple ( new SetPropertyValues ( clazz , propertyNames , setters ) ) )
268267 .method ( getPropertyNamesMethodName )
269- .intercept ( MethodCall . call ( new CloningPropertyCall ( propertyNames ) ) )
268+ .intercept ( new Implementation . Simple ( new GetPropertyNames ( propertyNames ) ) )
270269 );
271270 }
272271
@@ -1346,17 +1345,29 @@ private static Constructor<?> findConstructor(Class<?> clazz) {
13461345 }
13471346 }
13481347
1349- public static class CloningPropertyCall implements Callable < String []> {
1348+ public static class GetPropertyNames implements ByteCodeAppender {
13501349
13511350 private final String [] propertyNames ;
13521351
1353- private CloningPropertyCall (String [] propertyNames ) {
1352+ private GetPropertyNames (String [] propertyNames ) {
13541353 this .propertyNames = propertyNames ;
13551354 }
13561355
13571356 @ Override
1358- public String [] call () {
1359- return propertyNames .clone ();
1357+ public Size apply (
1358+ MethodVisitor methodVisitor ,
1359+ Implementation .Context implementationContext ,
1360+ MethodDescription instrumentedMethod ) {
1361+ methodVisitor .visitLdcInsn ( propertyNames .length );
1362+ methodVisitor .visitTypeInsn ( Opcodes .ANEWARRAY , Type .getInternalName ( String .class ) );
1363+ for ( int i = 0 ; i < propertyNames .length ; i ++ ) {
1364+ methodVisitor .visitInsn ( Opcodes .DUP );
1365+ methodVisitor .visitLdcInsn ( i );
1366+ methodVisitor .visitLdcInsn ( propertyNames [i ] );
1367+ methodVisitor .visitInsn ( Opcodes .AASTORE );
1368+ }
1369+ methodVisitor .visitInsn ( Opcodes .ARETURN );
1370+ return new Size ( 4 , instrumentedMethod .getStackSize () + 1 );
13601371 }
13611372 }
13621373
0 commit comments