diff --git a/core/src/main/java/lucee/runtime/reflection/Reflector.java b/core/src/main/java/lucee/runtime/reflection/Reflector.java index 8d135667ca..73933eab12 100755 --- a/core/src/main/java/lucee/runtime/reflection/Reflector.java +++ b/core/src/main/java/lucee/runtime/reflection/Reflector.java @@ -865,7 +865,7 @@ public static Object callMethod(Object obj, String methodName, Object[] args, bo } public static Object callMethod(final Object obj, Collection.Key methodName, Object[] args, boolean nameCaseSensitive) throws PageException { - return getMethodInstance(obj.getClass(), methodName, args, nameCaseSensitive, false).invoke(obj); + return MethodInstance.invoke(obj, methodName, args, nameCaseSensitive, true); } public static boolean hasMethod(Class clazz, String methodName, Object[] args, boolean nameCaseSensitive) { diff --git a/core/src/main/java/lucee/runtime/reflection/pairs/MethodInstance.java b/core/src/main/java/lucee/runtime/reflection/pairs/MethodInstance.java index 21e94454ac..ecfdbb32ca 100644 --- a/core/src/main/java/lucee/runtime/reflection/pairs/MethodInstance.java +++ b/core/src/main/java/lucee/runtime/reflection/pairs/MethodInstance.java @@ -87,6 +87,35 @@ public Object invoke(Object o) throws PageException { } } + public static Object invoke(Object obj, Key methodName, Object[] args, boolean nameCaseSensitive, boolean convertComparsion) throws PageException { + // if (Clazz.allowReflection()) print.e(Clazz.allowReflection()); + try { + return ((BiFunction) DynamicInvoker.getExistingInstance().getInstance(obj.getClass(), methodName, args, nameCaseSensitive, convertComparsion) + .getValue()).apply(obj, args); + } + catch (IncompatibleClassChangeError | ClassFormatError | ClassCastException e) { // java.lang.ClassCastException + if (!Clazz.allowReflection()) throw e; + LogUtil.log("dynamic", e); + DynamicInvoker di = DynamicInvoker.getExistingInstance(); + try { + lucee.transformer.dynamic.meta.Method method = Clazz.getMethodMatch(di.getClazz(obj.getClass(), true), methodName, args, nameCaseSensitive, true, true); + return ((LegacyMethod) method).getMethod().invoke(obj, args); + } + catch (Exception e1) { + if (e1 instanceof InvocationTargetException) { + Throwable t = ((InvocationTargetException) e1).getTargetException(); + ExceptionUtil.initCauseEL(e, t); + throw e; + } + ExceptionUtil.initCauseEL(e, e1); + throw e; + } + } + catch (Exception e) { + throw Caster.toPageException(e); + } + } + /** * @return Returns the args. */ diff --git a/core/src/main/java/lucee/runtime/util/VariableUtilImpl.java b/core/src/main/java/lucee/runtime/util/VariableUtilImpl.java index 26308798b9..e65043bb43 100755 --- a/core/src/main/java/lucee/runtime/util/VariableUtilImpl.java +++ b/core/src/main/java/lucee/runtime/util/VariableUtilImpl.java @@ -40,6 +40,7 @@ import lucee.runtime.op.Caster; import lucee.runtime.op.Decision; import lucee.runtime.reflection.Reflector; +import lucee.runtime.reflection.pairs.MethodInstance; import lucee.runtime.security.SecurityManager; import lucee.runtime.text.xml.XMLUtil; import lucee.runtime.text.xml.struct.XMLStructFactory; @@ -838,8 +839,9 @@ public Object callFunctionWithoutNamedValues(PageContext pc, Object coll, Collec if (pc.getConfig().getSecurityManager().getAccess(SecurityManager.TYPE_DIRECT_JAVA_ACCESS) == SecurityManager.VALUE_YES) { if (doLogReflectionCalls()) LogUtil.log(pc, Log.LEVEL_INFO, "reflection", "call-method:" + key + " from class " + Caster.toTypeName(coll)); if (!(coll instanceof Undefined)) { - return Reflector.getMethodInstance(coll.getClass(), key, args, false, false).invoke(coll); - // return Reflector.callMethod(coll, key, args); + // return Reflector.getMethodInstance(coll.getClass(), key, args, false, false).invoke(coll); + return MethodInstance.invoke(coll, key, args, false, true); + // return Reflector.callMethod(coll, key, args, false); } } throw new ExpressionException("No matching Method/Function for " + key + "(" + Reflector.getDspMethods(Reflector.getClasses(args)) + ")"); diff --git a/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java b/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java index 6c7515adb7..788799cbde 100644 --- a/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java +++ b/core/src/main/java/lucee/transformer/dynamic/DynamicInvoker.java @@ -464,7 +464,7 @@ public Pair createInstance2(Class clazz, Key methodNa return null; } - public static void main(String[] args) throws Throwable { + public static void main(String[] argsw) throws Throwable { System.setProperty("lucee.allow.reflection", "false"); Resource classes = ResourcesImpl.getFileResourceProvider().getResource("/Users/mic/tmp8/classes/"); ResourceUtil.deleteContent(classes, null); @@ -485,6 +485,7 @@ public static void main(String[] args) throws Throwable { TestMule tm = new TestMule(); Class clazz = tm.getClass(); Class[] cargs = new Class[] { int.class }; + Object[] args = new Object[] { 1 }; Key methodName = new KeyImpl("Test"); e.invokeConstructor(clazz, new Object[] { 1 }, false); e.invokeConstructor(String.class, new Object[] { "" }, false); @@ -493,7 +494,7 @@ public static void main(String[] args) throws Throwable { for (int i = 0; i < rounds; i++) { long start = System.currentTimeMillis(); for (int y = 0; y < max; y++) { - clazz.getMethod("test", cargs).invoke(tm, new Object[] { 1 }); + clazz.getMethod("test", cargs).invoke(tm, args); } tmp = System.currentTimeMillis() - start; if (tmp < reflection) reflection = tmp; @@ -503,7 +504,7 @@ public static void main(String[] args) throws Throwable { for (int i = 0; i < rounds; i++) { long start = System.currentTimeMillis(); for (int y = 0; y < max; y++) { - e.invokeInstanceMethod(tm, "test", new Object[] { 1 }, false, false); + e.invokeInstanceMethod(tm, methodName, args, false, false); } tmp = System.currentTimeMillis() - start; if (tmp < dynamicInvoker) dynamicInvoker = tmp; @@ -514,7 +515,7 @@ public static void main(String[] args) throws Throwable { long start = System.currentTimeMillis(); for (int y = 0; y < max; y++) { // Reflector.getMethodInstance(clazz, methodName, new Object[] { 1 }, false, false).invoke(tm); - Reflector.getMethod(clazz, "test", cargs, true).invoke(tm, new Object[] { 1 }); + Reflector.getMethod(clazz, "test", cargs, true).invoke(tm, args); } tmp = System.currentTimeMillis() - start; if (tmp < dynamicInvoker2) dynamicInvoker2 = tmp; @@ -524,7 +525,7 @@ public static void main(String[] args) throws Throwable { for (int i = 0; i < rounds; i++) { long start = System.currentTimeMillis(); for (int y = 0; y < max; y++) { - Reflector.callMethod(tm, methodName, new Object[] { 1 }, false); + Reflector.callMethod(tm, methodName, args, false); } tmp = System.currentTimeMillis() - start; if (tmp < dynamicInvoker3) dynamicInvoker3 = tmp; diff --git a/loader/build.xml b/loader/build.xml index 74295ae61f..3a198ac064 100644 --- a/loader/build.xml +++ b/loader/build.xml @@ -2,7 +2,7 @@ - + diff --git a/loader/pom.xml b/loader/pom.xml index 73121a6d03..f0e14bd5bc 100644 --- a/loader/pom.xml +++ b/loader/pom.xml @@ -3,7 +3,7 @@ org.lucee lucee - 6.2.0.228-SNAPSHOT + 6.2.0.229-SNAPSHOT jar Lucee Loader Build