Skip to content

[Bug] Wrong Spring plugin activated: Spring 6.x plugin incorrectly triggers for Spring 5.3.13 due to imprecise witness class #13342

Description

@zJiaJun

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

Java Agent (apache/skywalking-java)

What happened

The Spring 6.x plugin (mvc-annotation-6.x-plugin) is being incorrectly activated when using Spring Framework 5.3.13, causing runtime errors due to API incompatibilities between Spring 5.x and Spring 6.x.

The issue is in the witness class selection in AbstractSpring6Instrumentation:

// AbstractSpring6Instrumentation.java
public static final String WITNESS_CLASSES = "org.springframework.web.servlet.resource.HttpResource";

The HttpResource class exists in Spring Framework since version 5.0 (as documented here), making it an imprecise witness class for detecting Spring 6.x.

Error Details

ERROR 2025-06-26 12:06:24.943 XNIO-1 task-4 InstMethodsInter : class[class org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod] after method[getBean] intercept failure java.lang.NoSuchMethodError: org.springframework.web.context.request.ServletRequestAttributes.getRequest()Ljakarta/servlet/http/HttpServletRequest; at org.apache.skywalking.apm.plugin.spring.mvc.v6.GetBeanInterceptor.afterMethod(GetBeanInterceptor.java:51)

Analysis

  1. Spring 5.3.13 uses javax.servlet.* APIs
  2. Spring 6.x migrated to jakarta.servlet.* APIs
  3. The ServletRequestAttributes.getRequest() method returns different types:
    • Spring 5.x: javax.servlet.http.HttpServletRequest
    • Spring 6.x: jakarta.servlet.http.HttpServletRequest
  4. Since HttpResource exists in both Spring 5.x and 6.x, the witness class check passes incorrectly

What you expected to happen

  • Spring 5.x applications should activate the mvc-annotation-5.x-plugin
  • Spring 6.x applications should activate the mvc-annotation-6.x-plugin

How to reproduce

  • SkyWalking Version: 9.1.0
  • Spring Framework Version: 5.3.13
  • Java Version: 1.8

Anything else

Replace the witness class in AbstractSpring6Instrumentation with a class that only exists in Spring 6.x
Any recommended classes?

If my thinking is wrong, please tell me.

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Activity

  1. added
    bugSomething isn't working and you are sure it's a bug!
    on Jun 26, 2025
  2. locked and limited conversation to collaborators on Jun 26, 2025
  3. converted this issue into a discussion #13343 on Jun 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working and you are sure it's a bug!

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions