Skip to content

Commit

Permalink
graal: Don't initialize ResourceLeakDetector at build time (#7142)
Browse files Browse the repository at this point in the history
Fixes #7141
  • Loading branch information
yawkat committed Mar 25, 2022
1 parent c952759 commit 4e13d18
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.micronaut.core.annotation.Internal;
import io.micronaut.core.naming.NameUtils;
import io.micronaut.core.util.SupplierUtil;
import io.micronaut.http.MediaType;
import io.micronaut.http.multipart.CompletedFileUpload;
import io.netty.buffer.ByteBuf;
Expand All @@ -32,6 +33,7 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.Optional;
import java.util.function.Supplier;

/**
* A Netty implementation of {@link CompletedFileUpload}.
Expand All @@ -41,8 +43,9 @@
*/
@Internal
public class NettyCompletedFileUpload implements CompletedFileUpload {
private static final ResourceLeakDetector<NettyCompletedFileUpload> RESOURCE_LEAK_DETECTOR =
ResourceLeakDetectorFactory.instance().newResourceLeakDetector(NettyCompletedFileUpload.class);
//to avoid initializing Netty at build time
private static final Supplier<ResourceLeakDetector<NettyCompletedFileUpload>> RESOURCE_LEAK_DETECTOR = SupplierUtil.memoized(() ->
ResourceLeakDetectorFactory.instance().newResourceLeakDetector(NettyCompletedFileUpload.class));

private final FileUpload fileUpload;
private final boolean controlRelease;
Expand All @@ -65,7 +68,7 @@ public NettyCompletedFileUpload(FileUpload fileUpload, boolean controlRelease) {
this.controlRelease = controlRelease;
if (controlRelease) {
fileUpload.retain();
tracker = RESOURCE_LEAK_DETECTOR.track(this);
tracker = RESOURCE_LEAK_DETECTOR.get().track(this);
} else {
tracker = null;
}
Expand Down

0 comments on commit 4e13d18

Please sign in to comment.