|
19 | 19 | import datadog.trace.api.gateway.RequestContextSlot; |
20 | 20 | import datadog.trace.bootstrap.instrumentation.api.AgentSpan; |
21 | 21 | import datadog.trace.bootstrap.instrumentation.api.AgentTracer; |
| 22 | +import java.lang.reflect.Method; |
22 | 23 | import java.util.ArrayList; |
23 | 24 | import java.util.Collections; |
24 | 25 | import java.util.HashMap; |
@@ -57,6 +58,21 @@ public class BodyParserHelpers { |
57 | 58 | private static final Logger log = LoggerFactory.getLogger(BodyParserHelpers.class); |
58 | 59 | public static final int MAX_RECURSION = 15; |
59 | 60 |
|
| 61 | + // Cached via reflection to avoid embedding a hard binary reference to |
| 62 | + // files():Lscala/collection/Seq; — the return type changed to |
| 63 | + // Lscala/collection/immutable/Seq; in Scala 2.13 (Play 2.7+), which would |
| 64 | + // cause muzzle to disable the instrumentation for Play 2.7. |
| 65 | + private static final Method MULTIPART_FILES_METHOD; |
| 66 | + |
| 67 | + static { |
| 68 | + Method m = null; |
| 69 | + try { |
| 70 | + m = MultipartFormData.class.getMethod("files"); |
| 71 | + } catch (Exception ignored) { |
| 72 | + } |
| 73 | + MULTIPART_FILES_METHOD = m; |
| 74 | + } |
| 75 | + |
60 | 76 | private static JFunction1< |
61 | 77 | scala.collection.immutable.Map<String, Seq<String>>, |
62 | 78 | scala.collection.immutable.Map<String, Seq<String>>> |
@@ -127,12 +143,11 @@ private static MultipartFormData<?> handleMultipartFormData(MultipartFormData<?> |
127 | 143 | } |
128 | 144 |
|
129 | 145 | try { |
130 | | - // Use reflection to avoid a hard binary reference to files():Lscala/collection/Seq; — |
131 | | - // in Scala 2.13 (Play 2.7+) the return type became scala.collection.immutable.Seq, |
132 | | - // which would cause muzzle to disable the whole instrumentation for Play 2.7. |
133 | | - Object files = data.getClass().getMethod("files").invoke(data); |
134 | | - if (files instanceof scala.collection.Iterable) { |
135 | | - handleMultipartFilenames(((scala.collection.Iterable<?>) files).iterator()); |
| 146 | + if (MULTIPART_FILES_METHOD != null) { |
| 147 | + Object files = MULTIPART_FILES_METHOD.invoke(data); |
| 148 | + if (files instanceof scala.collection.Iterable) { |
| 149 | + handleMultipartFilenames(((scala.collection.Iterable<?>) files).iterator()); |
| 150 | + } |
136 | 151 | } |
137 | 152 | } catch (Exception e) { |
138 | 153 | handleException(e, "Error handling multipartFormData filenames"); |
|
0 commit comments