|
32 | 32 |
|
33 | 33 | import java.util.ArrayList; |
34 | 34 | import java.util.Arrays; |
| 35 | +import java.util.HashSet; |
35 | 36 | import java.util.List; |
| 37 | +import java.util.Set; |
36 | 38 | import java.util.regex.Matcher; |
37 | 39 | import java.util.regex.Pattern; |
38 | 40 |
|
@@ -79,10 +81,15 @@ private LambdaUtils() { |
79 | 81 | public static String findStableLambdaName(ResolvedJavaType lambdaType) { |
80 | 82 | ResolvedJavaMethod[] lambdaProxyMethods = Arrays.stream(lambdaType.getDeclaredMethods(false)).filter(m -> !m.isBridge() && m.isPublic()).toArray(ResolvedJavaMethod[]::new); |
81 | 83 | /* |
82 | | - * Take only the first method to find invoked methods, because the result would be the same |
83 | | - * for all other methods. |
| 84 | + * Traverse all methods in lambda class for invokes because it is possible a javaagent may |
| 85 | + * inject new methods into the lambda class. For example, Byte-buddy used by OTele can |
| 86 | + * transform all classes that implements {@link java.util.concurrent.Callable} by injecting |
| 87 | + * new methods that may not have any invokes. |
84 | 88 | */ |
85 | | - List<JavaMethod> invokedMethods = findInvokedMethods(lambdaProxyMethods[0]); |
| 89 | + Set<JavaMethod> invokedMethods = new HashSet<>(); |
| 90 | + for (int i = 0; i < lambdaProxyMethods.length; i++) { |
| 91 | + invokedMethods.addAll(findInvokedMethods(lambdaProxyMethods[i])); |
| 92 | + } |
86 | 93 | if (invokedMethods.isEmpty()) { |
87 | 94 | StringBuilder sb = new StringBuilder(); |
88 | 95 | sb.append("Lambda without a target invoke: ").append(lambdaType.toClassName()); |
@@ -141,7 +148,7 @@ public static boolean isLambdaName(String name) { |
141 | 148 | return isLambdaClassName(name) && lambdaMatcher(name).find(); |
142 | 149 | } |
143 | 150 |
|
144 | | - private static String createStableLambdaName(ResolvedJavaType lambdaType, List<JavaMethod> targetMethods) { |
| 151 | + private static String createStableLambdaName(ResolvedJavaType lambdaType, Set<JavaMethod> targetMethods) { |
145 | 152 | final String lambdaName = lambdaType.getName(); |
146 | 153 | assert lambdaMatcher(lambdaName).find() : "Stable name should be created for lambda types: " + lambdaName; |
147 | 154 |
|
|
0 commit comments