From 700b9b8e6bfa676b0ec2043bd2fdce17a2706272 Mon Sep 17 00:00:00 2001 From: Egor Ushakov Date: Fri, 13 Dec 2024 18:18:17 +0100 Subject: [PATCH] [debugger] prevent the exception garbage collection in helper GitOrigin-RevId: b85234a5a0d83ef25e04655abb65fb70664dcab9 --- .../src/com/intellij/rt/debugger/MethodInvoker.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/java/java-runtime/src/com/intellij/rt/debugger/MethodInvoker.java b/java/java-runtime/src/com/intellij/rt/debugger/MethodInvoker.java index 8aa0c40b1538..2cbd2ed4985c 100644 --- a/java/java-runtime/src/com/intellij/rt/debugger/MethodInvoker.java +++ b/java/java-runtime/src/com/intellij/rt/debugger/MethodInvoker.java @@ -9,7 +9,7 @@ import java.lang.invoke.WrongMethodTypeException; @SuppressWarnings({"SSBasedInspection", "unused"}) public final class MethodInvoker { // TODO: may leak objects here - static ThreadLocal returnValue = new ThreadLocal<>(); + static ThreadLocal keptValue = new ThreadLocal<>(); public static Object invoke0(MethodHandles.Lookup lookup, Class cls, Object obj, String nameAndDescriptor, ClassLoader loader) throws Throwable { @@ -207,11 +207,16 @@ public final class MethodInvoker { } Object result = method.invokeWithArguments(args); - returnValue.set(result); + keptValue.set(result); return result; } catch (WrongMethodTypeException | ClassCastException e) { e.printStackTrace(); + keptValue.set(e); + throw e; + } + catch (Throwable e) { + keptValue.set(e); throw e; } }