co.elastic.apm.agent.bci.bytebuddy.FailSafeDeclaredMethodsCompiler#compile(net.bytebuddy.description.type.TypeDefinition, net.bytebuddy.description.type.TypeDescription)
@Override
public MethodGraph.Linked compile(TypeDefinition typeDefinition, TypeDescription viewPoint) {
LinkedHashMap<MethodDescription.SignatureToken, MethodGraph.Node> nodes = new LinkedHashMap<MethodDescription.SignatureToken, MethodGraph.Node>();
for (MethodDescription methodDescription : typeDefinition.getDeclaredMethods()
.filter(
// ignores all methods which refer to unknown types
failSafe(
isVirtual()
.and(not(isBridge()))
.and(isVisibleTo(viewPoint))
.and(hasParameters(whereNone(hasType(not(isVisibleTo(viewPoint))))))
)
)
) {
nodes.put(methodDescription.asSignatureToken(), new MethodGraph.Node.Simple(methodDescription));
}
return new MethodGraph.Linked.Delegation(new MethodGraph.Simple(nodes), MethodGraph.Empty.INSTANCE, Collections.<TypeDescription, MethodGraph>emptyMap());
}
There is no check for the visibility of the return type of methods within this method, such as .and(returns(isVisibleTo(viewPoint)))
, which leads to failures in methodDescription.asSignatureToken()
when handling methods with return types that are not visible.
This issue commonly occurs when other javaagents inject methods into classes, and the return type is not visible to elastic-agent.
Should the Compiler safely skip these methods rather than causing a compile failure? I'm not sure if this is intentional by elastic or an oversight. Does anyone have insight into this? Thanks!