From a71e108395aa19da5c7de3b98ac61c9c80702f17 Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Wed, 3 Jun 2026 18:28:43 +0200 Subject: [PATCH] [bugfix] Make sure to close ByteBuddy Dynamic Type Builder --- .../exist/xquery/functions/fn/FunAnalyzeString.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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); }