From 570881298380847194914c7fe253c74c1d50855a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Onuki?= Date: Thu, 12 Oct 2023 19:10:52 -0400 Subject: [PATCH] Java 21 compatibility (#1546) --- .github/actions/setup-environment/action.yml | 6 ++-- .github/workflows/GHA-Functional-Tests.yaml | 2 +- .github/workflows/GHA-Unit-Tests.yaml | 2 +- .../workflows/Java-Instrumentation-Tests.yml | 18 +++++------ .github/workflows/Test-AITs.yml | 14 ++++---- build.gradle | 2 +- buildSrc/build.gradle | 4 +-- functional_test/build.gradle | 2 +- .../instrumentation/ClassLoaderTest.java | 4 +-- .../ClassRetransformBootstrapTest.java | 4 +-- .../CustomExtensionTestAddition.java | 4 +-- gradle.properties.gha | 2 +- gradle/script/java.gradle | 10 +++--- .../instrumentation/akka22/test/AkkaTest.java | 4 +-- .../akka/http/AkkaHttpRoutesTest.java | 2 +- .../akka/http/AkkaResponseWrapperTest.java | 4 +-- instrumentation/apache-log4j-1/README.md | 11 +++++++ instrumentation/apache-log4j-1/build.gradle | 4 --- .../log4j1/LoggingEventMapTest.java | 9 ++++-- .../org/apache/log4j/ContextDataTest.java | 4 +++ .../AsyncHttpClient2_0_0Tests.java | 2 +- .../AsyncHttpClient2_1_0Tests.java | 2 +- .../cassandra/CassandraInstrumented.java | 4 +-- .../cassandra/CassandraNoInstrumentation.java | 4 +-- instrumentation/jdbc-socket-jdk21/README.md | 3 ++ .../jdbc-socket-jdk21/build.gradle | 11 +++++++ .../java/java/net/Socket_Instrumentation.java | 32 +++++++++++++++++++ .../SocketChannel_Instrumentation.java | 32 +++++++++++++++++++ .../play2816/ServerInstrumentationTest.java | 4 +-- instrumentation/vertx-core-3.3.3/build.gradle | 2 +- instrumentation/vertx-core-3.4.1/build.gradle | 2 +- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- instrumentation/vertx-web-3.3.0/build.gradle | 2 +- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- .../nr/vertx/instrumentation/VertxUtil.java | 4 ++- .../agent/config/JavaVersionUtils.java | 7 ++-- .../agent/config/JavaVersionUtilsTest.java | 25 ++++++++------- settings.gradle | 3 +- ...eTest.java => Java21IncompatibleTest.java} | 4 +-- 44 files changed, 199 insertions(+), 84 deletions(-) create mode 100644 instrumentation/apache-log4j-1/README.md create mode 100644 instrumentation/jdbc-socket-jdk21/README.md create mode 100644 instrumentation/jdbc-socket-jdk21/build.gradle create mode 100644 instrumentation/jdbc-socket-jdk21/src/main/java/java/net/Socket_Instrumentation.java create mode 100644 instrumentation/jdbc-socket-jdk21/src/main/java/java/nio/channels/SocketChannel_Instrumentation.java rename test-annotations/src/main/java/com/newrelic/test/marker/{Java20IncompatibleTest.java => Java21IncompatibleTest.java} (57%) diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml index a685d2b290..d7903bd4f3 100644 --- a/.github/actions/setup-environment/action.yml +++ b/.github/actions/setup-environment/action.yml @@ -18,7 +18,7 @@ runs: with: distribution: 'temurin' java-version: | - 20 + 21 17 11 8 @@ -29,7 +29,7 @@ runs: sed -i -e "s|jdk8=8|jdk8=${JAVA_HOME_8_X64}| s|jdk11=11|jdk11=${JAVA_HOME_11_X64}| s|jdk17=17|jdk17=${JAVA_HOME_17_X64}| - s|jdk20=20|jdk20=${JAVA_HOME_20_X64}|" gradle.properties.gha + s|jdk21=21|jdk21=${JAVA_HOME_21_X64}|" gradle.properties.gha cat gradle.properties.gha >> gradle.properties - name: Setup Gradle @@ -39,7 +39,7 @@ runs: - name: Setup Gradle options shell: bash - run: echo "GRADLE_OPTIONS=--console=plain --parallel -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_20_X64" >> $GITHUB_ENV + run: echo "GRADLE_OPTIONS=--console=plain --parallel -Porg.gradle.java.installations.auto-detect=false -Porg.gradle.java.installations.fromEnv=JAVA_HOME_8_X64,JAVA_HOME_11_X64,JAVA_HOME_17_X64,JAVA_HOME_21_X64" >> $GITHUB_ENV - name: Download S3 instrumentation jar zip shell: bash diff --git a/.github/workflows/GHA-Functional-Tests.yaml b/.github/workflows/GHA-Functional-Tests.yaml index 6f8b64583d..c8f786c123 100644 --- a/.github/workflows/GHA-Functional-Tests.yaml +++ b/.github/workflows/GHA-Functional-Tests.yaml @@ -28,7 +28,7 @@ jobs: ##max-parallel: 1 ## used to force sequential fail-fast: false matrix: - java-version: [ 8, 11, 17, 20 ] + java-version: [8, 11, 17, 21] steps: - name: Checkout Java agent uses: actions/checkout@v3 diff --git a/.github/workflows/GHA-Unit-Tests.yaml b/.github/workflows/GHA-Unit-Tests.yaml index 9649a6d131..86ebb1e12a 100644 --- a/.github/workflows/GHA-Unit-Tests.yaml +++ b/.github/workflows/GHA-Unit-Tests.yaml @@ -25,7 +25,7 @@ jobs: # max-parallel: 1 ## used to force sequential vs. concurrent fail-fast: false matrix: - java-version: [8, 11, 17, 20] + java-version: [8, 11, 17, 21] steps: - name: Checkout Java agent uses: actions/checkout@v3 diff --git a/.github/workflows/Java-Instrumentation-Tests.yml b/.github/workflows/Java-Instrumentation-Tests.yml index 3780327457..704fc1e82f 100644 --- a/.github/workflows/Java-Instrumentation-Tests.yml +++ b/.github/workflows/Java-Instrumentation-Tests.yml @@ -20,8 +20,8 @@ jobs: strategy: fail-fast: false matrix: - jre: [8, 11, 17, 20] - name: Java ${{ matrix.jre }} + java-version: [8, 11, 17, 21] + name: Java ${{ matrix.java-version }} timeout-minutes: 120 # needs: install-all-java runs-on: ubuntu-20.04 @@ -55,29 +55,29 @@ jobs: # GHA run instrumentation tests - - name: Run instrumentation tests for Java ${{ matrix.jre }} (attempt 1) + - name: Run instrumentation tests for Java ${{ matrix.java-version }} (attempt 1) id: run_tests_1 continue-on-error: true timeout-minutes: 35 - run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.jre }} --continue + run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.java-version }} --continue - - name: Run instrumentation tests for Java ${{ matrix.jre }} (attempt 2) + - name: Run instrumentation tests for Java ${{ matrix.java-version }} (attempt 2) id: run_tests_2 continue-on-error: true timeout-minutes: 35 if: steps.run_tests_1.outcome == 'failure' - run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.jre }} --continue + run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.java-version }} --continue - - name: Run instrumentation tests for Java ${{ matrix.jre }} (attempt 3) + - name: Run instrumentation tests for Java ${{ matrix.java-version }} (attempt 3) timeout-minutes: 35 if: steps.run_tests_2.outcome == 'failure' - run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.jre }} --continue + run: ./gradlew $GRADLE_OPTIONS :instrumentation:test -Ptest${{ matrix.java-version }} --continue # Capture HTML build result in artifacts - name: Capture build reports if: ${{ failure() }} uses: actions/upload-artifact@v3 with: - name: instrumentation-tests-results-java-${{ matrix.jre }} + name: instrumentation-tests-results-java-${{ matrix.java-version }} path: | instrumentation/**/build/reports/tests/* diff --git a/.github/workflows/Test-AITs.yml b/.github/workflows/Test-AITs.yml index ee96a81c6e..4ce22f8af9 100644 --- a/.github/workflows/Test-AITs.yml +++ b/.github/workflows/Test-AITs.yml @@ -198,7 +198,7 @@ jobs: with: distribution: 'zulu' java-version: | - 20 + 21 17 11 @@ -207,14 +207,14 @@ jobs: run: | echo "JDK_zulu_11=${JAVA_HOME_11_X64}" >> $GITHUB_ENV echo "JDK_zulu_17=${JAVA_HOME_17_X64}" >> $GITHUB_ENV - echo "JDK_zulu_20=${JAVA_HOME_20_X64}" >> $GITHUB_ENV + echo "JDK_zulu_21=${JAVA_HOME_21_X64}" >> $GITHUB_ENV - name: Set up Javas uses: actions/setup-java@v3 with: distribution: 'temurin' java-version: | - 20 + 21 17 11 8 @@ -257,10 +257,10 @@ jobs: jdk - 20 + 21 - ${JAVA_HOME_20_X64} + ${JAVA_HOME_21_X64} @@ -291,11 +291,11 @@ jobs: bin/pip3 install -r conf/requirements.txt ZULU11=${JDK_zulu_11} \ ZULU17=${JDK_zulu_17} \ - ZULU20=${JDK_zulu_20} \ + ZULU21=${JDK_zulu_21} \ JAVA8JRE=${JAVA_HOME_8_X64} \ JAVA11JRE=${JAVA_HOME_11_X64} \ JAVA17JRE=${JAVA_HOME_17_X64} \ - JAVA20JRE=${JAVA_HOME_20_X64} \ + JAVA21JRE=${JAVA_HOME_21_X64} \ conf/autoconfigure . conf/testenv java cat conf/java_local_config.yml diff --git a/build.gradle b/build.gradle index fd3acdc5b9..447ac376eb 100644 --- a/build.gradle +++ b/build.gradle @@ -74,5 +74,5 @@ ext { // SynchronizedAnnotationNode, SynchronizedClassNode, SynchronizedFieldNode, SynchronizedInnerClassNode, SynchronizedMethodNode, // SynchronizedModuleExportNode, SynchronizedModuleNode, SynchronizedModuleOpenNode, SynchronizedModuleProvideNode, SynchronizedModuleRequireNode, // SynchronizedTypeAnnotationNode - asmVersion="9.5" + asmVersion="9.6" } diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index b596501f19..37af6f72fc 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -13,8 +13,8 @@ repositories { dependencies { // This is how we do our NR-specific patching. That is, moving Log4jPlugins, // changing Logger.getLogger, and checking for unmapped dependencies. - implementation("org.ow2.asm:asm:9.3") - implementation("org.ow2.asm:asm-commons:9.3") + implementation("org.ow2.asm:asm:9.6") + implementation("org.ow2.asm:asm-commons:9.6") // Shadow is used here because several classes implement the Transformer interface implementation("com.github.jengelman.gradle.plugins:shadow:6.0.0") diff --git a/functional_test/build.gradle b/functional_test/build.gradle index afdff12a24..62b4982915 100644 --- a/functional_test/build.gradle +++ b/functional_test/build.gradle @@ -102,7 +102,7 @@ test { //testLogging.showStandardStreams = true // when using an early access Java version, we need to pass an extra param to the agent - if (project.hasProperty("test21")) { + if (project.hasProperty("test22")) { jvmArgs += ["-Dnewrelic.config.experimental_runtime=true"] } diff --git a/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassLoaderTest.java b/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassLoaderTest.java index 98d3a5ff7a..d1cd94a133 100644 --- a/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassLoaderTest.java +++ b/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassLoaderTest.java @@ -12,7 +12,7 @@ import com.newrelic.api.agent.Trace; import com.newrelic.test.marker.IBMJ9IncompatibleTest; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -68,7 +68,7 @@ public void testMissingNewRelicClass() throws ClassNotFoundException { // Java 12 no longer lets us access the declared field @Test - @Category({ IBMJ9IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) + @Category({ IBMJ9IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) public void testSetSystemClassLoader() throws Exception { final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); diff --git a/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassRetransformBootstrapTest.java b/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassRetransformBootstrapTest.java index 2a82946c5f..9353fd790f 100644 --- a/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassRetransformBootstrapTest.java +++ b/functional_test/src/test/java/com/newrelic/agent/instrumentation/ClassRetransformBootstrapTest.java @@ -9,7 +9,7 @@ import com.newrelic.test.marker.Java11IncompatibleTest; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -17,7 +17,7 @@ import java.util.HashMap; import java.util.Map; -@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) public class ClassRetransformBootstrapTest { /** diff --git a/functional_test/src/test/java/com/newrelic/agent/instrumentation/CustomExtensionTestAddition.java b/functional_test/src/test/java/com/newrelic/agent/instrumentation/CustomExtensionTestAddition.java index 7484ab6be0..943b5dd077 100644 --- a/functional_test/src/test/java/com/newrelic/agent/instrumentation/CustomExtensionTestAddition.java +++ b/functional_test/src/test/java/com/newrelic/agent/instrumentation/CustomExtensionTestAddition.java @@ -12,14 +12,14 @@ import com.newrelic.api.agent.Trace; import com.newrelic.test.marker.Java11IncompatibleTest; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.Mockito; import javax.activation.MimeType; -@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) public class CustomExtensionTestAddition { @Test diff --git a/gradle.properties.gha b/gradle.properties.gha index 8234cac61d..ceac47ad9a 100644 --- a/gradle.properties.gha +++ b/gradle.properties.gha @@ -1,4 +1,4 @@ jdk8=8 jdk11=11 jdk17=17 -jdk20=20 +jdk21=21 diff --git a/gradle/script/java.gradle b/gradle/script/java.gradle index 5e56b673f7..49cebbbc82 100644 --- a/gradle/script/java.gradle +++ b/gradle/script/java.gradle @@ -96,7 +96,7 @@ test { ext.configuredWithValidTestJDK = { if (project.hasProperty("test9") || project.hasProperty("test10") || project.hasProperty("test12") || project.hasProperty("test13") || project.hasProperty("test14") || project.hasProperty("test15") || project.hasProperty("test16") || project.hasProperty("test18") || - project.hasProperty("test19")) { + project.hasProperty("test19") || project.hasProperty("test20")) { logger.lifecycle("The newrelic-java-agent project does not support testing with the Java version configured by the -PtestN gradle property.") return false } @@ -117,8 +117,8 @@ test { configuration.call() } - if (project.hasProperty("test20")) { - configureTest("jdk20") { + if (project.hasProperty("test21")) { + configureTest("jdk21") { jvmArgs '--add-opens=java.base/java.lang=ALL-UNNAMED', '--add-opens=java.base/java.util=ALL-UNNAMED', '--add-opens=java.base/java.net=ALL-UNNAMED', @@ -127,9 +127,11 @@ test { '--add-exports=java.base/sun.net.spi=ALL-UNNAMED', '--add-exports=java.xml/com.sun.org.apache.xalan.internal.xsltc.trax=ALL-UNNAMED' useJUnit { - excludeCategories 'com.newrelic.test.marker.Java20IncompatibleTest' + excludeCategories 'com.newrelic.test.marker.Java21IncompatibleTest' } } + // mockito uses a version of bytebuddy that has experimental support for Java 21 + systemProperty("net.bytebuddy.experimental", "true") } if (project.hasProperty("test17")) { configureTest("jdk17") { diff --git a/instrumentation/akka-2.2/src/test/java/com/nr/instrumentation/akka22/test/AkkaTest.java b/instrumentation/akka-2.2/src/test/java/com/nr/instrumentation/akka22/test/AkkaTest.java index f00ddb87de..f27a03e1e2 100644 --- a/instrumentation/akka-2.2/src/test/java/com/nr/instrumentation/akka22/test/AkkaTest.java +++ b/instrumentation/akka-2.2/src/test/java/com/nr/instrumentation/akka22/test/AkkaTest.java @@ -13,7 +13,7 @@ import com.newrelic.agent.introspec.Introspector; import com.newrelic.agent.introspec.TracedMetricData; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import com.nr.instrumentation.akka22.test.actors.broadcasting.ActorA; import com.nr.instrumentation.akka22.test.actors.broadcasting.ActorB; import com.nr.instrumentation.akka22.test.actors.broadcasting.ActorC; @@ -32,7 +32,7 @@ import static org.junit.Assert.assertTrue; // Not compatible with Java 11+ and Scala 2.13+ https://github.com/scala/bug/issues/12340 -@Category({ Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"akka.actor", "akka.dispatch", "akka.pattern", "akka.routing"}) public class AkkaTest { diff --git a/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java b/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java index 2983c9915b..f88a9c51bd 100644 --- a/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java +++ b/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaHttpRoutesTest.java @@ -30,7 +30,7 @@ import static org.hamcrest.Matchers.containsString; // Not compatible with Java 11+ and Scala 2.13+ https://github.com/scala/bug/issues/12340 -@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"akka", "scala", "com.agent", "com.nr"}) public class AkkaHttpRoutesTest { diff --git a/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaResponseWrapperTest.java b/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaResponseWrapperTest.java index 687d1e9652..8d92a706d9 100644 --- a/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaResponseWrapperTest.java +++ b/instrumentation/akka-http-2.11_2.4.5/src/test/java/com/agent/instrumentation/akka/http/AkkaResponseWrapperTest.java @@ -13,7 +13,7 @@ import com.newrelic.agent.introspec.TransactionEvent; import com.newrelic.test.marker.Java11IncompatibleTest; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -29,7 +29,7 @@ import static org.junit.Assert.assertTrue; // Not compatible with Java 11+ and Scala 2.13+ https://github.com/scala/bug/issues/12340 -@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"akka", "scala"}) public class AkkaResponseWrapperTest { diff --git a/instrumentation/apache-log4j-1/README.md b/instrumentation/apache-log4j-1/README.md new file mode 100644 index 0000000000..f4710a04be --- /dev/null +++ b/instrumentation/apache-log4j-1/README.md @@ -0,0 +1,11 @@ +# Log4J1 instrumentation + +## Regarding ignored tests under Java 21 + +Log4J1 supposes it is running on Java 1 unless the Java version has a `.` followed by a number different than `1`. +When it runs on Java 1, it does not set MDC entries. + +Corretto distribution of Java 21(.0.0) returns "21" when `System.getProperty("java.version")` is invoked. + +So when running our tests with Java 21, MDC will not work. Thus our tests will fail. +It is likely that this will be fixed when 21.0.1 is released. At which point we could re-enable the tests. \ No newline at end of file diff --git a/instrumentation/apache-log4j-1/build.gradle b/instrumentation/apache-log4j-1/build.gradle index b1e6d88f31..0390b1ee73 100644 --- a/instrumentation/apache-log4j-1/build.gradle +++ b/instrumentation/apache-log4j-1/build.gradle @@ -21,7 +21,3 @@ site { title 'Log4j-1' type 'Framework' } - -test { - useJUnitPlatform() -} \ No newline at end of file diff --git a/instrumentation/apache-log4j-1/src/test/java/com/nr/agent/instrumentation/log4j1/LoggingEventMapTest.java b/instrumentation/apache-log4j-1/src/test/java/com/nr/agent/instrumentation/log4j1/LoggingEventMapTest.java index beb9d4565f..8cdfbe571c 100644 --- a/instrumentation/apache-log4j-1/src/test/java/com/nr/agent/instrumentation/log4j1/LoggingEventMapTest.java +++ b/instrumentation/apache-log4j-1/src/test/java/com/nr/agent/instrumentation/log4j1/LoggingEventMapTest.java @@ -10,6 +10,7 @@ import com.newrelic.agent.bridge.logging.AppLoggingUtils; import com.newrelic.agent.bridge.logging.LogAttributeKey; import com.newrelic.agent.bridge.logging.LogAttributeType; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.apache.log4j.Category; import org.apache.log4j.MDC; import org.apache.log4j.Priority; @@ -22,9 +23,13 @@ import java.util.Map; import java.util.stream.Stream; -import static org.junit.jupiter.api.Assertions.*; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +// Log4J1 has a quirk with Java 21(.0.0), maybe this will work when 21.0.1 is released +@org.junit.experimental.categories.Category({ Java21IncompatibleTest.class}) public class LoggingEventMapTest { private static Stream providerParamsForLoggingEventMapTest() { diff --git a/instrumentation/apache-log4j-1/src/test/java/org/apache/log4j/ContextDataTest.java b/instrumentation/apache-log4j-1/src/test/java/org/apache/log4j/ContextDataTest.java index c866c482a4..f87819e9b3 100644 --- a/instrumentation/apache-log4j-1/src/test/java/org/apache/log4j/ContextDataTest.java +++ b/instrumentation/apache-log4j-1/src/test/java/org/apache/log4j/ContextDataTest.java @@ -10,8 +10,10 @@ import com.newrelic.agent.introspec.InstrumentationTestRunner; import com.newrelic.agent.introspec.Introspector; import com.newrelic.agent.model.LogEvent; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.junit.Before; import org.junit.Test; +import org.junit.experimental.categories.Category; import org.junit.runner.RunWith; import java.util.Collection; @@ -19,6 +21,8 @@ import static org.junit.Assert.assertEquals; +// Log4J1 has a quirk with Java 21(.0.0), maybe this will work when 21.0.1 is released +@Category({Java21IncompatibleTest.class}) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"org.apache.log4j"}, configName = "application_logging_context_data_enabled.yml") public class ContextDataTest { diff --git a/instrumentation/async-http-client-2.0.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_0_0Tests.java b/instrumentation/async-http-client-2.0.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_0_0Tests.java index d995ba4476..320bfdbcef 100644 --- a/instrumentation/async-http-client-2.0.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_0_0Tests.java +++ b/instrumentation/async-http-client-2.0.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_0_0Tests.java @@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.nr.agent.instrumentation.asynchttpclient", "org.asynchttpclient"}) public class AsyncHttpClient2_0_0Tests { diff --git a/instrumentation/async-http-client-2.1.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_1_0Tests.java b/instrumentation/async-http-client-2.1.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_1_0Tests.java index b8afbe2677..544d4c7d88 100644 --- a/instrumentation/async-http-client-2.1.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_1_0Tests.java +++ b/instrumentation/async-http-client-2.1.0/src/test/java/com/nr/agent/instrumentation/asynchttpclient/AsyncHttpClient2_1_0Tests.java @@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = {"com.nr.agent.instrumentation.asynchttpclient", "org.asynchttpclient"}) public class AsyncHttpClient2_1_0Tests { diff --git a/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraInstrumented.java b/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraInstrumented.java index bf0e3647f3..373c57158a 100644 --- a/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraInstrumented.java +++ b/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraInstrumented.java @@ -17,7 +17,7 @@ import com.newrelic.test.marker.IBMJ9IncompatibleTest; import com.newrelic.test.marker.Java11IncompatibleTest; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.cassandraunit.CassandraCQLUnit; import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; import org.junit.Rule; @@ -33,7 +33,7 @@ import static org.junit.Assert.assertNotNull; // Issue when running cassandra unit on Java 9+ - https://github.com/jsevellec/cassandra-unit/issues/249 -@Category({ IBMJ9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ IBMJ9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "com.datastax.oss.driver" }) public class CassandraInstrumented { diff --git a/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraNoInstrumentation.java b/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraNoInstrumentation.java index 9e2ffe82c3..94e9ce4d57 100644 --- a/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraNoInstrumentation.java +++ b/instrumentation/cassandra-datastax-4.0.0/src/test/java/com/nr/agent/instrumentation/cassandra/CassandraNoInstrumentation.java @@ -15,7 +15,7 @@ import com.newrelic.test.marker.IBMJ9IncompatibleTest; import com.newrelic.test.marker.Java11IncompatibleTest; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.cassandraunit.CassandraCQLUnit; import org.cassandraunit.dataset.cql.ClassPathCQLDataSet; import org.junit.Rule; @@ -26,7 +26,7 @@ import static org.junit.Assert.assertEquals; // Issue when running cassandra unit on Java 9+ - https://github.com/jsevellec/cassandra-unit/issues/249 -@Category({ IBMJ9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ IBMJ9IncompatibleTest.class, Java11IncompatibleTest.class, Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "none" }) public class CassandraNoInstrumentation { diff --git a/instrumentation/jdbc-socket-jdk21/README.md b/instrumentation/jdbc-socket-jdk21/README.md new file mode 100644 index 0000000000..2e7b339d75 --- /dev/null +++ b/instrumentation/jdbc-socket-jdk21/README.md @@ -0,0 +1,3 @@ +# jdbc-socket-jdk21 + +In Java 21, the implementation for Socket has changed. diff --git a/instrumentation/jdbc-socket-jdk21/build.gradle b/instrumentation/jdbc-socket-jdk21/build.gradle new file mode 100644 index 0000000000..eb12e53789 --- /dev/null +++ b/instrumentation/jdbc-socket-jdk21/build.gradle @@ -0,0 +1,11 @@ +dependencies { + implementation(project(":agent-bridge")) + implementation(project(":agent-bridge-datastore")) +} + +jar { + manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.jdbc-socket-jdk21' } +} + +verifyInstrumentation { +} diff --git a/instrumentation/jdbc-socket-jdk21/src/main/java/java/net/Socket_Instrumentation.java b/instrumentation/jdbc-socket-jdk21/src/main/java/java/net/Socket_Instrumentation.java new file mode 100644 index 0000000000..34fb22608b --- /dev/null +++ b/instrumentation/jdbc-socket-jdk21/src/main/java/java/net/Socket_Instrumentation.java @@ -0,0 +1,32 @@ +/* + * + * * Copyright 2023 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + +package java.net; + +import com.newrelic.agent.bridge.datastore.DatastoreInstanceDetection; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; + +@Weave(originalName = "java.net.Socket") +public class Socket_Instrumentation { + + // There are some static methods that could be used instead of these constants. + // But to use those methods, we'd add some intrumentation to them, adding to the overhead + // of something that should be really fast. + private static final int BOUND = Weaver.callOriginal(); + private static final int CONNECTED = Weaver.callOriginal(); + private volatile int state = Weaver.callOriginal(); + + public void connect(SocketAddress endpoint, int timeout) { + Weaver.callOriginal(); + boolean connected = (state & CONNECTED) != 0; + boolean bound = (state & BOUND) != 0; + if (connected && bound && DatastoreInstanceDetection.shouldDetectConnectionAddress() && (endpoint instanceof InetSocketAddress)) { + DatastoreInstanceDetection.saveAddress((InetSocketAddress) endpoint); + } + } +} diff --git a/instrumentation/jdbc-socket-jdk21/src/main/java/java/nio/channels/SocketChannel_Instrumentation.java b/instrumentation/jdbc-socket-jdk21/src/main/java/java/nio/channels/SocketChannel_Instrumentation.java new file mode 100644 index 0000000000..5b2263bcac --- /dev/null +++ b/instrumentation/jdbc-socket-jdk21/src/main/java/java/nio/channels/SocketChannel_Instrumentation.java @@ -0,0 +1,32 @@ +/* + * + * * Copyright 2023 New Relic Corporation. All rights reserved. + * * SPDX-License-Identifier: Apache-2.0 + * + */ + +package java.nio.channels; + +import com.newrelic.agent.bridge.datastore.DatastoreInstanceDetection; +import com.newrelic.agent.bridge.datastore.JdbcHelper; +import com.newrelic.api.agent.weaver.MatchType; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; + +import java.net.InetSocketAddress; +import java.net.SocketAddress; + +@Weave(originalName = "java.nio.channels.SocketChannel", type = MatchType.BaseClass) +public abstract class SocketChannel_Instrumentation { + + public static SocketChannel_Instrumentation open(SocketAddress remote) { + SocketChannel_Instrumentation channel = Weaver.callOriginal(); + + if (channel.isConnected() && DatastoreInstanceDetection.shouldDetectConnectionAddress() && (remote instanceof InetSocketAddress)) { + DatastoreInstanceDetection.saveAddress((InetSocketAddress) remote); + } + return channel; + } + + public abstract boolean isConnected(); +} diff --git a/instrumentation/play-2.8.16/src/test/java/com/nr/agent/instrumentation/play2816/ServerInstrumentationTest.java b/instrumentation/play-2.8.16/src/test/java/com/nr/agent/instrumentation/play2816/ServerInstrumentationTest.java index 2d7375727a..4f8e008b85 100644 --- a/instrumentation/play-2.8.16/src/test/java/com/nr/agent/instrumentation/play2816/ServerInstrumentationTest.java +++ b/instrumentation/play-2.8.16/src/test/java/com/nr/agent/instrumentation/play2816/ServerInstrumentationTest.java @@ -12,7 +12,7 @@ import com.newrelic.agent.introspec.Introspector; import com.newrelic.agent.introspec.TracedMetricData; import com.newrelic.test.marker.Java17IncompatibleTest; -import com.newrelic.test.marker.Java20IncompatibleTest; +import com.newrelic.test.marker.Java21IncompatibleTest; import org.junit.Rule; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -@Category({ Java17IncompatibleTest.class, Java20IncompatibleTest.class }) +@Category({ Java17IncompatibleTest.class, Java21IncompatibleTest.class }) @RunWith(InstrumentationTestRunner.class) @InstrumentationTestConfig(includePrefixes = { "com.nr.agent.instrumentation.play2816", "play" }) public class ServerInstrumentationTest { diff --git a/instrumentation/vertx-core-3.3.3/build.gradle b/instrumentation/vertx-core-3.3.3/build.gradle index de05b746b2..37a85ff04d 100644 --- a/instrumentation/vertx-core-3.3.3/build.gradle +++ b/instrumentation/vertx-core-3.3.3/build.gradle @@ -15,7 +15,7 @@ verifyInstrumentation { test { // this version of Vert.x uses some DirectBuffer things that are now hidden in its module - if (project.hasProperty("test17") || project.hasProperty("test20")) { + if (project.hasProperty("test17") || project.hasProperty("test21")) { jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' } diff --git a/instrumentation/vertx-core-3.4.1/build.gradle b/instrumentation/vertx-core-3.4.1/build.gradle index 5d9a8642b4..6de5290d69 100644 --- a/instrumentation/vertx-core-3.4.1/build.gradle +++ b/instrumentation/vertx-core-3.4.1/build.gradle @@ -19,7 +19,7 @@ verifyInstrumentation { test { // this version of Vert.x uses some DirectBuffer things that are now hidden in its module - if (project.hasProperty("test17") || project.hasProperty("test20")) { + if (project.hasProperty("test17") || project.hasProperty("test21")) { jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' } diff --git a/instrumentation/vertx-web-3.2.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.2.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 34ccd649a7..f374a2483d 100644 --- a/instrumentation/vertx-web-3.2.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.2.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -29,7 +29,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/instrumentation/vertx-web-3.3.0/build.gradle b/instrumentation/vertx-web-3.3.0/build.gradle index 66757ff875..d729028aea 100644 --- a/instrumentation/vertx-web-3.3.0/build.gradle +++ b/instrumentation/vertx-web-3.3.0/build.gradle @@ -24,7 +24,7 @@ verifyInstrumentation { test { // this version of Vert.x uses some DirectBuffer things that are now hidden in its module - if (project.hasProperty("test17") || project.hasProperty("test20")) { + if (project.hasProperty("test17") || project.hasProperty("test21")) { jvmArgs += '--add-opens=java.base/java.nio=ALL-UNNAMED' jvmArgs += '--add-opens=java.base/sun.nio.ch=ALL-UNNAMED' } diff --git a/instrumentation/vertx-web-3.3.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.3.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 34ccd649a7..f374a2483d 100644 --- a/instrumentation/vertx-web-3.3.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.3.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -29,7 +29,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/instrumentation/vertx-web-3.5.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.5.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 6de13a752f..a5fe876c6a 100644 --- a/instrumentation/vertx-web-3.5.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.5.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -31,7 +31,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/instrumentation/vertx-web-3.5.1/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.5.1/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 6de13a752f..a5fe876c6a 100644 --- a/instrumentation/vertx-web-3.5.1/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.5.1/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -31,7 +31,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/instrumentation/vertx-web-3.5.2/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.5.2/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 6de13a752f..a5fe876c6a 100644 --- a/instrumentation/vertx-web-3.5.2/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.5.2/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -31,7 +31,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/instrumentation/vertx-web-3.6.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.6.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 6de13a752f..a5fe876c6a 100644 --- a/instrumentation/vertx-web-3.6.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.6.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -31,7 +31,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/instrumentation/vertx-web-3.8.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.8.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 180451261b..92ec05542a 100644 --- a/instrumentation/vertx-web-3.8.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.8.0/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -32,7 +32,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/instrumentation/vertx-web-3.8.3/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java b/instrumentation/vertx-web-3.8.3/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java index 180451261b..92ec05542a 100644 --- a/instrumentation/vertx-web-3.8.3/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java +++ b/instrumentation/vertx-web-3.8.3/src/main/java/com/nr/vertx/instrumentation/VertxUtil.java @@ -32,7 +32,9 @@ public class VertxUtil { private static final String FRAMEWORK = "Vertx"; private static final String NEWRELIC_PATH = "newrelic-path"; - private static final Pattern lambda = Pattern.compile("\\$\\$Lambda\\$.*"); + // Java < 21 = org.example.Class$$Lambda$14/0x0000000800000a08@3ac42916 + // Java >= 21 = org.example.Class$$Lambda/0x00000008000c2a00@6442b0a6 + private static final Pattern lambda = Pattern.compile("\\$\\$Lambda(\\$[^/]*)?/.*"); private static final Pattern instance = Pattern.compile("@.*"); private VertxUtil() { diff --git a/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java b/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java index 72eaed9a82..c4b024efb5 100644 --- a/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java +++ b/newrelic-agent/src/main/java/com/newrelic/agent/config/JavaVersionUtils.java @@ -14,10 +14,10 @@ */ public class JavaVersionUtils { // For Java 21 - 29, the regex should be updated to utilize a range like the 10-19 version check does - private static final Pattern SUPPORTED_JAVA_VERSION_PATTERN = Pattern.compile("^(1\\.8|9|1[0-9]|20)$"); + private static final Pattern SUPPORTED_JAVA_VERSION_PATTERN = Pattern.compile("^(1\\.8|9|1[0-9]|2[0-1])$"); private static final Pattern EXCLUSIVE_MIN_JAVA_VERSION_PATTERN = Pattern.compile("^1\\.7$"); - private static final Pattern EXCLUSIVE_MAX_JAVA_VERSION_PATTERN = Pattern.compile("^21$"); - private static final String MAX_SUPPORTED_VERSION = "20"; + private static final Pattern EXCLUSIVE_MAX_JAVA_VERSION_PATTERN = Pattern.compile("^22$"); + private static final String MAX_SUPPORTED_VERSION = "21"; public static final String JAVA_7 = "1.7"; public static final String JAVA_8 = "1.8"; @@ -34,6 +34,7 @@ public class JavaVersionUtils { public static final String JAVA_19 = "19"; public static final String JAVA_20 = "20"; public static final String JAVA_21 = "21"; + public static final String JAVA_22 = "22"; public static String getJavaSpecificationVersion() { diff --git a/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java b/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java index a6dd5330d0..94a52a24f9 100644 --- a/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java +++ b/newrelic-agent/src/test/java/com/newrelic/agent/config/JavaVersionUtilsTest.java @@ -32,6 +32,7 @@ public void supportAgentJavaSpecVersions() { assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_18)); assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_19)); assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_20)); + assertTrue(JavaVersionUtils.isAgentSupportedJavaSpecVersion(JavaVersionUtils.JAVA_21)); } @Test @@ -55,14 +56,14 @@ public void unsupportedAgentVersionsLessThanJava8() { @Test public void javaVersionHigherThanSupported() { - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21.0")); - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21+181")); - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21.0+181")); - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21.0_b181")); - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21.0.1")); - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21.0.1+11")); - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21.0.1_11")); - assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("21.0.1_11-b11")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22.0")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22+181")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22.0+181")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22.0_b181")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22.0.1")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22.0.1+11")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22.0.1_11")); + assertFalse(JavaVersionUtils.isAgentSupportedJavaSpecVersion("22.0.1_11-b11")); } @Test @@ -89,9 +90,9 @@ public void unsupportedJavaVersionMessageWhenLessThanMinimalSupportedVersion() { @Test public void unsupportedJavaVersionMessageWhenGreaterThanMaxSupportedVersion() { - String msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_21); - assertThat(msg, containsString(JavaVersionUtils.JAVA_21)); - assertThat(msg, containsString("Java greater than 20.")); + String msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_22); + assertThat(msg, containsString(JavaVersionUtils.JAVA_22)); + assertThat(msg, containsString("Java greater than 21.")); } @Test @@ -99,7 +100,7 @@ public void emptyMessageReturnedWhenJavaVersionSupported() { String msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_8); assertEquals(0, msg.length()); - msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_20); + msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(JavaVersionUtils.JAVA_21); assertEquals(0, msg.length()); msg = JavaVersionUtils.getUnsupportedAgentJavaSpecVersionMessage(null); diff --git a/settings.gradle b/settings.gradle index b221ac20f7..79dbd387a1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -155,7 +155,6 @@ include 'instrumentation:jdbc-driver' include 'instrumentation:jdbc-embedded-derby-10.11.1.1' include 'instrumentation:jdbc-embedded-derby-10.15.1.3' include 'instrumentation:jdbc-generic' -include 'instrumentation:jdbc-socket' include 'instrumentation:jdbc-h2' include 'instrumentation:jdbc-hsqldb-1.7.2.2' include 'instrumentation:jdbc-hsqldb-2.2.9' @@ -182,6 +181,8 @@ include 'instrumentation:jdbc-postgresql-8.0-312.jdbc3' include 'instrumentation:jdbc-postgresql-9.4.1207' include 'instrumentation:jdbc-postgresql-9.4.1208' include 'instrumentation:jdbc-resultset' +include 'instrumentation:jdbc-socket' +include 'instrumentation:jdbc-socket-jdk21' include 'instrumentation:jdbc-sqlserver' include 'instrumentation:jdbc-sybase-6' include 'instrumentation:jedis-1.4.0' diff --git a/test-annotations/src/main/java/com/newrelic/test/marker/Java20IncompatibleTest.java b/test-annotations/src/main/java/com/newrelic/test/marker/Java21IncompatibleTest.java similarity index 57% rename from test-annotations/src/main/java/com/newrelic/test/marker/Java20IncompatibleTest.java rename to test-annotations/src/main/java/com/newrelic/test/marker/Java21IncompatibleTest.java index b629ff8e3b..228f4bc714 100644 --- a/test-annotations/src/main/java/com/newrelic/test/marker/Java20IncompatibleTest.java +++ b/test-annotations/src/main/java/com/newrelic/test/marker/Java21IncompatibleTest.java @@ -1,7 +1,7 @@ package com.newrelic.test.marker; /** - * Marker interface to denote a unit/functional/instrumentation test that is incompatible with Java 20. + * Marker interface to denote a unit/functional/instrumentation test that is incompatible with Java 21. */ -public interface Java20IncompatibleTest { +public interface Java21IncompatibleTest { }