From 387e1521f070c0051d170f4a833ade69bd713471 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Mon, 8 Jul 2019 16:15:25 -0700 Subject: [PATCH] Fix getCallerClass methods to acquire the correct frame --- .../oracle/svm/core/jdk/StackTraceUtils.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java index 3387cc7f3c80..ce6143ef38a9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/StackTraceUtils.java @@ -128,19 +128,24 @@ class GetCallerClassVisitor extends JavaStackFrameVisitor { @Override public boolean visitFrame(FrameInfoQueryResult frameInfo) { - if (!StackTraceUtils.shouldShowFrame(frameInfo, false, false)) { + if (!foundCallee) { /* - * Always ignore the frame. It is an internal frame of the VM or a frame related to - * reflection. + * Skip the frame that contained the invocation of getCallerFrame() and continue the + * stack walk. Note that this could be a frame related to reflection, but we still must + * not ignore it: For example, Constructor.newInstance calls Reflection.getCallerClass + * and for this check Constructor.newInstance counts as a frame. But if the actual + * invoked constructor calls Reflection.getCallerClass, then Constructor.newInstance + * does not count as as frame (handled by the shouldShowFrame check below because this + * path was already taken for the constructor frame). */ + foundCallee = true; return true; - } else if (!foundCallee) { + } else if (!StackTraceUtils.shouldShowFrame(frameInfo, false, false)) { /* - * Skip the frame that contained the invocation of getCallerFrame() and continue the - * stack walk. + * Always ignore the frame. It is an internal frame of the VM or a frame related to + * reflection. */ - foundCallee = true; return true; } else {