From 007b06e9db44ff889147a1993702289f304467ae Mon Sep 17 00:00:00 2001 From: Roland Praml Date: Thu, 18 Jul 2019 23:12:07 +0200 Subject: [PATCH] use local lookup instead of public lookup (#1764) (cherry picked from commit dc0441aaea126efc23a9c2abc30a4dd67bac6752) --- .../server/dto/DtoMetaConstructor.java | 31 ++++++++++--------- .../server/dto/DtoMetaProperty.java | 5 +-- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/ebeaninternal/server/dto/DtoMetaConstructor.java b/src/main/java/io/ebeaninternal/server/dto/DtoMetaConstructor.java index 05aec36b6..79a5ee307 100644 --- a/src/main/java/io/ebeaninternal/server/dto/DtoMetaConstructor.java +++ b/src/main/java/io/ebeaninternal/server/dto/DtoMetaConstructor.java @@ -12,11 +12,13 @@ import java.sql.SQLException; class DtoMetaConstructor { - private final Class[] types; - private final MethodHandle handle; + private final Class[] types; + private final MethodHandle handle; + + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); private final ScalarType[] scalarTypes; - DtoMetaConstructor(TypeManager typeManager, Constructor constructor, Class someClass) throws NoSuchMethodException, IllegalAccessException { + DtoMetaConstructor(TypeManager typeManager, Constructor constructor, Class someClass) throws NoSuchMethodException, IllegalAccessException { this.types = constructor.getParameterTypes(); this.scalarTypes = new ScalarType[types.length]; @@ -24,13 +26,12 @@ class DtoMetaConstructor { scalarTypes[i] = typeManager.getScalarType(types[i]); } - MethodHandles.Lookup lookup = MethodHandles.publicLookup(); - this.handle = lookup.findConstructor(someClass, typeFor(types)); - } + this.handle = LOOKUP.findConstructor(someClass, typeFor(types)); + } - private MethodType typeFor(Class[] types) { - return MethodType.methodType(void.class, types); - } + private MethodType typeFor(Class[] types) { + return MethodType.methodType(void.class, types); + } Class[] getTypes() { return types; @@ -48,7 +49,7 @@ class DtoMetaConstructor { } } - public Object process(DataReader dataReader) throws SQLException { + public Object process(DataReader dataReader) throws SQLException { Object[] values = new Object[scalarTypes.length]; for (int i = 0; i < scalarTypes.length; i++) { values[i] = scalarTypes[i].read(dataReader); @@ -56,12 +57,12 @@ class DtoMetaConstructor { return invoke(values); } - private Object invoke(Object... args) { - try { - return handle.invokeWithArguments(args); + private Object invoke(Object... args) { + try { + return handle.invokeWithArguments(args); } catch (Throwable e) { - throw new RuntimeException("Unexpected error invoking constructor", e); + throw new RuntimeException("Unexpected error invoking constructor", e); } - } + } } diff --git a/src/main/java/io/ebeaninternal/server/dto/DtoMetaProperty.java b/src/main/java/io/ebeaninternal/server/dto/DtoMetaProperty.java index 3b672b100..69182e08b 100644 --- a/src/main/java/io/ebeaninternal/server/dto/DtoMetaProperty.java +++ b/src/main/java/io/ebeaninternal/server/dto/DtoMetaProperty.java @@ -13,6 +13,8 @@ import java.sql.SQLException; class DtoMetaProperty implements DtoReadSet { + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); + private final Class dtoType; private final String name; private final MethodHandle setter; @@ -28,8 +30,7 @@ class DtoMetaProperty implements DtoReadSet { Class propertyType = descriptor.getPropertyType(); - MethodHandles.Lookup lookup = MethodHandles.publicLookup(); - this.setter = lookup.findVirtual(dtoType, writeMethod.getName(), MethodType.methodType(void.class, propertyType)); + this.setter = LOOKUP.findVirtual(dtoType, writeMethod.getName(), MethodType.methodType(void.class, propertyType)); this.scalarType = typeManager.getScalarType(propertyType); } else {