Skip to content

Commit a71e108

Browse files
committed
[bugfix] Make sure to close ByteBuddy Dynamic Type Builder
1 parent 825e1c4 commit a71e108

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

exist-core/src/main/java/org/exist/xquery/functions/fn/FunAnalyzeString.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import java.util.List;
5555

5656
import net.bytebuddy.ByteBuddy;
57+
import net.bytebuddy.dynamic.DynamicType;
5758
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
5859
import net.bytebuddy.implementation.InvocationHandlerAdapter;
5960
import net.bytebuddy.matcher.ElementMatchers;
@@ -277,14 +278,15 @@ private static Class<? extends AbstractSaxonRegexMatchHandler> createSaxon9Match
277278
}
278279

279280
private static Class<? extends AbstractSaxonRegexMatchHandler> createSaxonMatchHandlerClass(final Class<?> saxonMatchHandlerInterface) throws IllegalStateException{
280-
try {
281-
return new ByteBuddy().subclass(AbstractSaxonRegexMatchHandler.class)
281+
try (final DynamicType.Unloaded<AbstractSaxonRegexMatchHandler> unloadedAbstractSaxonRegexMatchHandler = new ByteBuddy().subclass(AbstractSaxonRegexMatchHandler.class)
282282
.implement(saxonMatchHandlerInterface)
283283
.method(ElementMatchers.named("characters"))
284284
.intercept(InvocationHandlerAdapter.of(CHARACTERS_HANDLER))
285-
.make()
286-
.load(AbstractSaxonRegexMatchHandler.class.getClassLoader(), ClassLoadingStrategy.UsingLookup.of(MethodHandles.privateLookupIn(AbstractSaxonRegexMatchHandler.class, java.lang.invoke.MethodHandles.lookup())))
287-
.getLoaded();
285+
.make()) {
286+
287+
return unloadedAbstractSaxonRegexMatchHandler
288+
.load(AbstractSaxonRegexMatchHandler.class.getClassLoader(), ClassLoadingStrategy.UsingLookup.of(MethodHandles.privateLookupIn(AbstractSaxonRegexMatchHandler.class, java.lang.invoke.MethodHandles.lookup())))
289+
.getLoaded();
288290
} catch (final IllegalAccessException e) {
289291
throw new IllegalStateException("Unable to obtain lookup for dynamic Saxon Match Handler class: " + e.getMessage(), e);
290292
}

0 commit comments

Comments
 (0)