From 5e17283ce6780728c6524ecd47709cb23e978863 Mon Sep 17 00:00:00 2001 From: Liam Miller-Cushon Date: Mon, 5 May 2025 13:21:17 -0700 Subject: [PATCH] Prepare MethodInterceptionTest for an upcoming JDK version PiperOrigin-RevId: 755050401 --- core/test/com/google/inject/MethodInterceptionTest.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/test/com/google/inject/MethodInterceptionTest.java b/core/test/com/google/inject/MethodInterceptionTest.java index cc81c49857..d1b1dff1f7 100644 --- a/core/test/com/google/inject/MethodInterceptionTest.java +++ b/core/test/com/google/inject/MethodInterceptionTest.java @@ -305,7 +305,7 @@ protected void configure() { StackTraceElement[] stackTraceElement = t.getStackTrace(); int frame = 0; assertEquals("explode", stackTraceElement[frame++].getMethodName()); - while (stackTraceElement[frame].getClassName().startsWith("java.lang.invoke.LambdaForm")) { + while (isLambdaFrame(stackTraceElement[frame])) { frame++; // ignore lambda frames when running tests with ShowHiddenFrames } assertEquals("invoke", stackTraceElement[frame++].getMethodName()); @@ -315,6 +315,12 @@ protected void configure() { } } + private static boolean isLambdaFrame(StackTraceElement element) { + var name = element.getClassName(); + return name.startsWith("java.lang.invoke.LambdaForm") + || name.startsWith("java.lang.invoke.DirectMethodHandle"); + } + @Test public void testNotInterceptedMethodsInInterceptedClassDontAddFrames() { Injector injector =