diff --git a/exist-core/src/main/java/org/exist/repo/ExistRepository.java b/exist-core/src/main/java/org/exist/repo/ExistRepository.java index 830e902af62..bbb0187a85d 100644 --- a/exist-core/src/main/java/org/exist/repo/ExistRepository.java +++ b/exist-core/src/main/java/org/exist/repo/ExistRepository.java @@ -10,9 +10,7 @@ package org.exist.repo; import java.io.IOException; -import java.lang.invoke.LambdaMetafactory; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; +import java.lang.reflect.Constructor; import java.net.URI; import java.net.URISyntaxException; import java.nio.file.Files; @@ -20,8 +18,6 @@ import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.*; -import java.util.function.Function; -import java.util.function.Supplier; import javax.xml.transform.Source; import javax.xml.transform.stream.StreamSource; @@ -44,8 +40,6 @@ import org.expath.pkg.repo.Repository; import org.expath.pkg.repo.URISpace; -import static java.lang.invoke.MethodType.methodType; - /** * A repository as viewed by eXist. * @@ -57,7 +51,6 @@ public class ExistRepository extends Observable implements BrokerPoolService { private final static Logger LOG = LogManager.getLogger(ExistRepository.class); - private final static MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); public final static String EXPATH_REPO_DIR = "expathrepo"; public final static String EXPATH_REPO_DEFAULT = "webapp/WEB-INF/" + EXPATH_REPO_DIR; @@ -153,25 +146,13 @@ private Module instantiateModule(final Class clazz) throws XPathExceptio try { try { // attempt for a constructor that takes 1 argument - final MethodHandle methodHandle = LOOKUP.findConstructor(clazz, methodType(void.class, Map.class)); - final Function ctor = (Function) - LambdaMetafactory.metafactory( - LOOKUP, "apply", methodType(Function.class), - methodHandle.type().erase(), methodHandle, methodHandle.type()).getTarget().invokeExact(); - return ctor.apply(Collections.emptyMap()); + final Constructor cstr1 = clazz.getConstructor(Map.class); + return cstr1.newInstance(Collections.emptyMap()); } catch (final NoSuchMethodException nsme) { // attempt for a constructor that takes 0 arguments - final MethodHandle methodHandle = LOOKUP.findConstructor(clazz, methodType(void.class, Map.class)); - final Supplier ctor = (Supplier) - LambdaMetafactory.metafactory( - LOOKUP, "apply", methodType(Supplier.class), - methodHandle.type().erase(), methodHandle, methodHandle.type()).getTarget().invokeExact(); - return ctor.get(); + return clazz.newInstance(); } - } catch (final NoSuchMethodException nsme) { - throw new XPathException("Cannot find suitable constructor " + - "for module from EXPath repository: " + clazz.getName(), nsme); } catch (final Throwable e) { if (e instanceof InterruptedException) { // NOTE: must set interrupted flag @@ -179,7 +160,7 @@ private Module instantiateModule(final Class clazz) throws XPathExceptio } throw new XPathException("Unable to instantiate module from EXPath" + - "repository: " + clazz.getName()); + "repository: " + clazz.getName(), e); } } diff --git a/exist-core/src/main/java/org/exist/xquery/Function.java b/exist-core/src/main/java/org/exist/xquery/Function.java index f34dfe9e1ae..84ae478bc26 100644 --- a/exist-core/src/main/java/org/exist/xquery/Function.java +++ b/exist-core/src/main/java/org/exist/xquery/Function.java @@ -19,9 +19,7 @@ */ package org.exist.xquery; -import java.lang.invoke.LambdaMetafactory; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; +import java.lang.reflect.Constructor; import java.util.List; import org.exist.dom.QName; @@ -34,8 +32,6 @@ import org.exist.xquery.value.SequenceType; import org.exist.xquery.value.Type; -import static java.lang.invoke.MethodType.methodType; - /** * Abstract base class for all built-in and user-defined functions. *

@@ -52,8 +48,6 @@ */ public abstract class Function extends PathExpr { - private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); - // Declare it in Namespaces instead? /ljo public final static String BUILTIN_FUNCTION_NS = "http://www.w3.org/2005/xpath-functions"; @@ -135,22 +129,14 @@ public static Function createFunction(final XQueryContext context, final XQueryA Function function = null; try { // attempt for a constructor that takes 1 argument - final MethodHandle methodHandle = LOOKUP.findConstructor(fclazz, methodType(void.class, XQueryContext.class)); - final java.util.function.Function ctor = (java.util.function.Function) - LambdaMetafactory.metafactory( - LOOKUP, "apply", methodType(java.util.function.Function.class), - methodHandle.type().erase(), methodHandle, methodHandle.type()).getTarget().invokeExact(); - function = ctor.apply(context); + final Constructor cstr1 = fclazz.getConstructor(XQueryContext.class); + function = cstr1.newInstance(context); } catch (final NoSuchMethodException nsme1) { try { // attempt for a constructor that takes 2 arguments - final MethodHandle methodHandle = LOOKUP.findConstructor(fclazz, methodType(void.class, XQueryContext.class, FunctionSignature.class)); - final java.util.function.BiFunction ctor = (java.util.function.BiFunction) - LambdaMetafactory.metafactory( - LOOKUP, "apply", methodType(java.util.function.BiFunction.class), - methodHandle.type().erase(), methodHandle, methodHandle.type()).getTarget().invokeExact(); - function = ctor.apply(context, def.getSignature()); + final Constructor cstr2 = fclazz.getConstructor(XQueryContext.class, FunctionSignature.class); + function = cstr2.newInstance(context, def.getSignature()); } catch (final NoSuchMethodException nsme2) { throw new XPathException(ast.getLine(), ast.getColumn(), "Constructor not found"); } diff --git a/exist-core/src/main/java/org/exist/xquery/XQueryContext.java b/exist-core/src/main/java/org/exist/xquery/XQueryContext.java index 70748f89187..5c744051261 100644 --- a/exist-core/src/main/java/org/exist/xquery/XQueryContext.java +++ b/exist-core/src/main/java/org/exist/xquery/XQueryContext.java @@ -21,9 +21,7 @@ import java.io.IOException; import java.io.Reader; -import java.lang.invoke.LambdaMetafactory; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; +import java.lang.reflect.Constructor; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -93,7 +91,7 @@ import org.exist.xquery.value.*; import org.w3c.dom.Node; -import static java.lang.invoke.MethodType.methodType; +import static com.evolvedbinary.j8fu.tuple.Tuple.Tuple; import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE; import static javax.xml.XMLConstants.XML_NS_PREFIX; import static org.exist.Namespaces.XML_NS; @@ -1472,13 +1470,15 @@ private Module instantiateModule(final String namespaceURI, final Class final Map>> moduleParameters) { Module module = null; try { - final MethodHandles.Lookup lookup = MethodHandles.lookup(); - final MethodHandle methodHandle = lookup.findConstructor(mClazz, methodType(void.class, Map.class)); - final java.util.function.Function ctor = (java.util.function.Function) - LambdaMetafactory.metafactory( - lookup, "apply", methodType(java.util.function.Function.class), - methodHandle.type().erase(), methodHandle, methodHandle.type()).getTarget().invokeExact(); - module = ctor.apply(moduleParameters.get(namespaceURI)); + try { + // attempt for a constructor that takes 1 argument + final Constructor cstr1 = mClazz.getConstructor(Map.class); + module = cstr1.newInstance(moduleParameters.get(namespaceURI)); + + } catch (final NoSuchMethodException nsme) { + // attempt for a constructor that takes 0 arguments + module = mClazz.newInstance(); + } if (namespaceURI != null && !module.getNamespaceURI().equals(namespaceURI)) { LOG.warn("the module declares a different namespace URI. Expected: " + namespaceURI + " found: " + module.getNamespaceURI());