From ed0eeb1dcaedc7c20e0f265e731a5f843593cf54 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 3 Oct 2017 13:04:21 +0300 Subject: [PATCH] debugger agent: workaround for java 9 --- .../rt/debugger/agent/CaptureStorage.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java index 0038414efd5b..1f9019a3212c 100644 --- a/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java +++ b/java/debugger/debugger-agent-storage/src/com/intellij/rt/debugger/agent/CaptureStorage.java @@ -24,7 +24,6 @@ public class CaptureStorage { return new LinkedList(); } }; - private static final JavaLangAccess ourJavaLangAccess = SharedSecrets.getJavaLangAccess(); private static boolean DEBUG = false; private static boolean ENABLED = true; @@ -62,7 +61,7 @@ public class CaptureStorage { CapturedStack stack = STORAGE.get(new WeakKey(key)); Deque currentStacks = CURRENT_STACKS.get(); if (stack != null) { - currentStacks.add(new InsertMatch(stack, ourJavaLangAccess.getStackTraceDepth(new Throwable()))); + currentStacks.add(new InsertMatch(stack, getStackTraceDepth(new Throwable()))); if (DEBUG) { System.out.println("insert -> " + key + ", stack saved (" + currentStacks.size() + ")"); } @@ -191,4 +190,20 @@ public class CaptureStorage { public static void setEnabled(boolean enabled) { ENABLED = enabled; } + + private static final JavaLangAccess ourJavaLangAccess; + static { + JavaLangAccess access = null; + try { + access = SharedSecrets.getJavaLangAccess(); + } + catch (Throwable e) { + // java 9 + } + ourJavaLangAccess = access; + } + // TODO: this is a workaround for java 9 where SharedSecrets are not available + private static int getStackTraceDepth(Throwable exception) { + return ourJavaLangAccess != null ? ourJavaLangAccess.getStackTraceDepth(exception) : exception.getStackTrace().length; + } }