diff --git a/exist-core/src/main/java/org/exist/xquery/functions/fn/FunAnalyzeString.java b/exist-core/src/main/java/org/exist/xquery/functions/fn/FunAnalyzeString.java index 8d8804be04..f42ba69e65 100644 --- a/exist-core/src/main/java/org/exist/xquery/functions/fn/FunAnalyzeString.java +++ b/exist-core/src/main/java/org/exist/xquery/functions/fn/FunAnalyzeString.java @@ -54,6 +54,7 @@ import java.util.List; import net.bytebuddy.ByteBuddy; +import net.bytebuddy.dynamic.DynamicType; import net.bytebuddy.dynamic.loading.ClassLoadingStrategy; import net.bytebuddy.implementation.InvocationHandlerAdapter; import net.bytebuddy.matcher.ElementMatchers; @@ -277,14 +278,15 @@ private static Class createSaxon9Match } private static Class createSaxonMatchHandlerClass(final Class saxonMatchHandlerInterface) throws IllegalStateException{ - try { - return new ByteBuddy().subclass(AbstractSaxonRegexMatchHandler.class) + try (final DynamicType.Unloaded unloadedAbstractSaxonRegexMatchHandler = new ByteBuddy().subclass(AbstractSaxonRegexMatchHandler.class) .implement(saxonMatchHandlerInterface) .method(ElementMatchers.named("characters")) .intercept(InvocationHandlerAdapter.of(CHARACTERS_HANDLER)) - .make() - .load(AbstractSaxonRegexMatchHandler.class.getClassLoader(), ClassLoadingStrategy.UsingLookup.of(MethodHandles.privateLookupIn(AbstractSaxonRegexMatchHandler.class, java.lang.invoke.MethodHandles.lookup()))) - .getLoaded(); + .make()) { + + return unloadedAbstractSaxonRegexMatchHandler + .load(AbstractSaxonRegexMatchHandler.class.getClassLoader(), ClassLoadingStrategy.UsingLookup.of(MethodHandles.privateLookupIn(AbstractSaxonRegexMatchHandler.class, java.lang.invoke.MethodHandles.lookup()))) + .getLoaded(); } catch (final IllegalAccessException e) { throw new IllegalStateException("Unable to obtain lookup for dynamic Saxon Match Handler class: " + e.getMessage(), e); }