6565import java .io .File ;
6666import java .io .FileNotFoundException ;
6767import java .io .IOException ;
68+ import java .lang .instrument .Instrumentation ;
6869import java .net .URISyntaxException ;
6970import java .net .URL ;
7071import java .util .ArrayList ;
@@ -2951,19 +2952,32 @@ public void captureExpressionsWithCaptureLimits() throws IOException, URISyntaxE
29512952 }
29522953
29532954 @ Test
2954- public void methodParametersAttribute () throws IOException , URISyntaxException {
2955+ public void methodParametersAttribute () throws Exception {
29552956 final String CLASS_NAME = "CapturedSnapshot01" ;
2957+ Config config = mock (Config .class );
2958+ when (config .isDebuggerCodeOriginEnabled ()).thenReturn (false );
2959+ when (config .isDebuggerExceptionEnabled ()).thenReturn (false );
2960+ when (config .isDynamicInstrumentationEnabled ()).thenReturn (false );
2961+ Instrumentation inst = mock (Instrumentation .class );
2962+ if (JavaVirtualMachine .isJavaVersion (17 )) {
2963+ // on JDK 17 introduced Spring6 class
2964+ Class <?> springClass =
2965+ Class .forName (
2966+ "org.springframework.web.bind.annotation.ControllerMappingReflectiveProcessor" );
2967+ when (inst .getAllLoadedClasses ()).thenReturn (new Class [] {springClass });
2968+ } else {
2969+ when (inst .getAllLoadedClasses ()).thenReturn (new Class [0 ]);
2970+ }
2971+ DebuggerAgent .run (config , inst , null );
29562972 TestSnapshotListener listener =
29572973 installMethodProbeAtExit (CLASS_NAME , "main" , "int (java.lang.String)" );
29582974 Map <String , byte []> buffers =
29592975 compile (CLASS_NAME , SourceCompiler .DebugInfo .ALL , "8" , Arrays .asList ("-parameters" ));
29602976 Class <?> testClass = loadClass (CLASS_NAME , buffers );
29612977 int result = Reflect .onClass (testClass ).call ("main" , "1" ).get ();
29622978 assertEquals (3 , result );
2963- if (JavaVirtualMachine .isJavaVersionAtLeast (19 )) {
2964- Snapshot snapshot = assertOneSnapshot (listener );
2965- assertCaptureArgs (snapshot .getCaptures ().getReturn (), "arg" , String .class .getTypeName (), "1" );
2966- } else {
2979+ if (JavaVirtualMachine .isJavaVersion (17 )) {
2980+ // on JDK 17 with Spring6 class, transformation cannot happen
29672981 assertEquals (0 , listener .snapshots .size ());
29682982 ArgumentCaptor <ProbeId > probeIdCaptor = ArgumentCaptor .forClass (ProbeId .class );
29692983 ArgumentCaptor <String > strCaptor = ArgumentCaptor .forClass (String .class );
@@ -2972,6 +2986,9 @@ public void methodParametersAttribute() throws IOException, URISyntaxException {
29722986 assertEquals (
29732987 "Instrumentation failed for CapturedSnapshot01: java.lang.RuntimeException: Method Parameters attribute detected, instrumentation not supported" ,
29742988 strCaptor .getAllValues ().get (0 ));
2989+ } else {
2990+ Snapshot snapshot = assertOneSnapshot (listener );
2991+ assertCaptureArgs (snapshot .getCaptures ().getReturn (), "arg" , String .class .getTypeName (), "1" );
29752992 }
29762993 }
29772994
0 commit comments