Skip to content

Commit

Permalink
Traverse all methods in lambda class for stable name
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyilin committed Jan 3, 2025
1 parent c75ffbb commit 9f4b679
Showing 1 changed file with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -79,10 +81,14 @@ private LambdaUtils() {
public static String findStableLambdaName(ResolvedJavaType lambdaType) {
ResolvedJavaMethod[] lambdaProxyMethods = Arrays.stream(lambdaType.getDeclaredMethods(false)).filter(m -> !m.isBridge() && m.isPublic()).toArray(ResolvedJavaMethod[]::new);
/*
* Take only the first method to find invoked methods, because the result would be the same
* for all other methods.
* Traverse all methods in lambda class for invokes because it is possible a javaagent may inject new methods into
* the lambda class. For example, Byte-buddy used by OTele can transform all classes that implements
* {@link java.util.concurrent.Callable} by injecting new methods that may not have any invokes.
*/
List<JavaMethod> invokedMethods = findInvokedMethods(lambdaProxyMethods[0]);
Set<JavaMethod> invokedMethods = new HashSet<>();
for (int i = 0; i < lambdaProxyMethods.length; i++) {
invokedMethods.addAll(findInvokedMethods(lambdaProxyMethods[i]));
}
if (invokedMethods.isEmpty()) {
StringBuilder sb = new StringBuilder();
sb.append("Lambda without a target invoke: ").append(lambdaType.toClassName());
Expand Down Expand Up @@ -141,7 +147,7 @@ public static boolean isLambdaName(String name) {
return isLambdaClassName(name) && lambdaMatcher(name).find();
}

private static String createStableLambdaName(ResolvedJavaType lambdaType, List<JavaMethod> targetMethods) {
private static String createStableLambdaName(ResolvedJavaType lambdaType, Set<JavaMethod> targetMethods) {
final String lambdaName = lambdaType.getName();
assert lambdaMatcher(lambdaName).find() : "Stable name should be created for lambda types: " + lambdaName;

Expand Down

0 comments on commit 9f4b679

Please sign in to comment.