Skip to content

Commit 98d39fa

Browse files
committed
Fix Spring MVC plugin: check javax and jakarta servlet independently
When both javax.servlet and jakarta.servlet exist on the classpath (e.g., Spring MVC 6.x app with javax.servlet as transitive dependency), the exclusive if/else in the static initializer set IS_JAVAX=true and skipped the Jakarta check. At runtime, the request was jakarta type but IS_JAKARTA was false, causing IllegalStateException("this line should not be reached"). Fix: check both servlet APIs independently. Both IS_JAVAX and IS_JAKARTA can be true. The runtime isAssignableFrom checks on the actual request object type already select the correct branch.
1 parent 856a656 commit 98d39fa

File tree

1 file changed

+11
-9
lines changed
  • apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor

1 file changed

+11
-9
lines changed

apm-sniffer/apm-sdk-plugin/spring-plugins/mvc-annotation-commons/src/main/java/org/apache/skywalking/apm/plugin/spring/mvc/commons/interceptor/AbstractMethodInterceptor.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,21 @@ public abstract class AbstractMethodInterceptor implements InstanceMethodsAround
7474
AbstractMethodInterceptor.class.getClassLoader(),
7575
JAKARTA_SERVLET_RESPONSE_CLASS, GET_STATUS_METHOD
7676
);
77+
// Check both javax and jakarta independently — both may exist on the classpath.
78+
// For example, a Spring MVC 6.x (Jakarta) app may have javax.servlet as a
79+
// transitive dependency. The runtime request type determines which path is used.
7780
try {
7881
Class.forName(SERVLET_RESPONSE_CLASS, true, AbstractMethodInterceptor.class.getClassLoader());
79-
IN_SERVLET_CONTAINER = true;
8082
IS_JAVAX = true;
83+
IN_SERVLET_CONTAINER = true;
84+
} catch (Exception ignore) {
85+
}
86+
try {
87+
Class.forName(
88+
JAKARTA_SERVLET_RESPONSE_CLASS, true, AbstractMethodInterceptor.class.getClassLoader());
89+
IS_JAKARTA = true;
90+
IN_SERVLET_CONTAINER = true;
8191
} catch (Exception ignore) {
82-
try {
83-
Class.forName(
84-
JAKARTA_SERVLET_RESPONSE_CLASS, true, AbstractMethodInterceptor.class.getClassLoader());
85-
IN_SERVLET_CONTAINER = true;
86-
IS_JAKARTA = true;
87-
} catch (Exception ignore2) {
88-
IN_SERVLET_CONTAINER = false;
89-
}
9092
}
9193
}
9294

0 commit comments

Comments
 (0)