Skip to content

Instruction audit: Use exact compatibility method-handle lookups and declaring-class loaders - #21584

Open
otelbot[bot] wants to merge 1 commit into
mainfrom
otelbot/instruction-audit-46159092397
Open

otelbot[bot] wants to merge 1 commit into
mainfrom
otelbot/instruction-audit-46159092397

Conversation

@otelbot

@otelbot otelbot Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a finding from an instruction audit run that checked the following repository rule:

For compatibility code that needs a method handle, use findStatic or findVirtual when
the supported signatures are known. Enumerate known version-specific alternatives rather than using
reflection to remove compatibility branches. Resolve non-JDK signature types without initialization
through the method's declaring-class loader, for example
Class.forName(name, false, declaringClass.getClassLoader()), rather than the helper's loader.

Explanation

Replace broad reflective lookup for known compatibility methods with exact method-handle lookup, and resolve optional signature types through their declaring types without initializing them. This avoids resolution of unrelated member dependencies and incompatible signature classes in mixed-loader applications. Existing version alternatives, optional-method fallbacks, and invocation behavior are retained.

@otelbot
otelbot Bot requested a review from a team as a code owner November 28, 2026 15:26
@opentelemetry-pr-dashboard

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-11-28 15:26 UTC

Review the latest changes.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The current MethodHandles.lookup() call can impose incompatible RequestPath class-loader constraints, causing LinkageError and breaking application startup in mixed Spring parent/child-loader setups.

1 open issue
What changed in this PR

Updates compatibility helpers across instrumentation modules to reduce unrelated class resolution and improve behavior with mixed library versions and class loaders.

Changes:

  • Replaces reflective discovery with exact method-handle lookups for known signatures.
  • Resolves optional signature types through declaring-class loaders without initialization.
  • Applies loader-aware resolution to shared Spring test helpers.
File Description
OpenTelemetryHandlerMappingFilter.java Uses exact lookup for Spring MVC path parsing.
AbstractSpringWebfluxClientInstrumentationTest.java Loads status types through the client response loader.
WebfluxServerHttpAttributesGetter.java Uses the server response loader for status lookup.
StatusCodes.java Uses the client response loader for status lookup.
AbstractSpringKafkaTest.java Resolves the legacy future type through Kafka operations.
ServerCallAccess.java Resolves server-call alternatives through the request loader.
ConfigServerTargetUtil30.java Tries exact address-getter signatures for supported return types.
ChatCompletionEventsHelper.java Uses declaring-class loaders for tool-call signature types.
KafkaUtil.java Loads consumer-group metadata through the consumer loader.
MetroServerSpanNameUpdater.java Uses exact lookups for servlet path accessors.
CouchbaseQueryText.java Resolves the statement type through the query loader.
RequestAccess.java Uses the target class loader for Lambda configuration lookup.
RegistryCapturingClusterWrapper.java Uses exact lookups for both Dubbo cluster-join signatures.

Review effort: Balanced

Class.forName("org.springframework.http.server.RequestPath", false, classLoader);
Class<?> servletRequestClass =
Class.forName("javax.servlet.http.HttpServletRequest", false, classLoader);
return MethodHandles.lookup()

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant