Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 4, 2025

Replaces all occurrences of Function<X, X> with the more semantically appropriate UnaryOperator<X> in non-stable modules throughout the codebase.

Motivation

UnaryOperator<T> is a specialization of Function<T, T> that more clearly expresses the intent of operations that transform a value of the same type. Using UnaryOperator makes the code more readable and self-documenting.

Changes

This PR updates the following areas:

Core Infrastructure

  • TypeTransformer API: Changed Function<Advice.WithCustomMapping, Advice.WithCustomMapping> to UnaryOperator<Advice.WithCustomMapping> in the javaagent extension API and all implementations
  • Muzzle: Updated AdviceClassNameCollector to use UnaryOperator

Instrumentation Modules

  • Cassandra 4.0/4.4: Changed CompletionStageFunction to implement UnaryOperator<Object>
  • Elasticsearch REST 7.0: Updated proxy factory from Function<RestClient, RestClient> to UnaryOperator<RestClient>
  • JMX Metrics: Changed unit converter from Function<Number, Number> to UnaryOperator<Number>
  • OpenTelemetry API Bridge: Updated context bridging to use UnaryOperator<Object>
  • Reactor 3.1: Changed context propagation operators to use:
    • UnaryOperator<Runnable> for schedule hooks
    • UnaryOperator<reactor.util.context.Context> for context transformations
  • Resources: Changed MainJarPathFinder to use UnaryOperator<String> for system property lookups

Test Updates

Updated corresponding test files to use UnaryOperator in type declarations and casts where appropriate.

Scope

✅ Only modified unstable modules (no changes to stable APIs)
✅ All affected modules compile successfully
✅ No behavioral changes - purely a refactoring for code clarity

Fixes #[issue-number] (originally suggested in #13776 (comment))

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • maven.restlet.talend.com
  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED --add-opens=java.base/java.time=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-9.1.0-bin/9agqghryom9wkf8r80qlhnts3/gradle-9.1.0/lib/gradle-daemon-main-9.1.0.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-9.1.0-bin/9agqghryom9wkf8r80qlhnts3/gradle-9.1.0/lib/agents/gradle-instrumentation-agent-9.1.0.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 9.1.0 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Explore using UnaryOperator instead of Function<X, X></issue_title>
<issue_description>Originally posted by @trask in #13776 (comment)
</issue_description>

<agent_instructions>Look for all usages of Function<X, X> and replace them with UnaryOperator, as long as the module isn’t marked stable</agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes #14891

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Explore using UnaryOperator<X> instead of Function<X, X> Replace Function<X, X> with UnaryOperator<X> in unstable modules Oct 4, 2025
@Copilot Copilot AI requested a review from trask October 4, 2025 04:36
Copilot finished work on behalf of trask October 4, 2025 04:36
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.

Explore using UnaryOperator<X> instead of Function<X, X>
2 participants