Build with jdk21 (#11219)

This commit is contained in:
Lauri Tulmin 2024-05-01 17:17:21 +03:00 committed by GitHub
parent c92955fa2f
commit dfc79ebece
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
30 changed files with 131 additions and 62 deletions

View File

@ -69,7 +69,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2

View File

@ -35,7 +35,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2
@ -68,7 +68,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2
@ -138,7 +138,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Increase gradle daemon heap size
run: |
@ -220,7 +220,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
# vaadin 14 tests fail with node 18
- name: Set up Node
@ -335,7 +335,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Set up Gradle cache
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2
@ -388,7 +388,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2
@ -411,7 +411,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Set up Gradle cache
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2

View File

@ -70,7 +70,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2

View File

@ -27,7 +27,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Initialize CodeQL
uses: github/codeql-action/init@d39d31e687223d841ef683f52467bd88e9b21c14 # v3.25.3

View File

@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Increase gradle daemon heap size
run: |

View File

@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2
@ -49,7 +49,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2

View File

@ -40,7 +40,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Set up Gradle cache
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2

View File

@ -22,7 +22,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Login to GitHub package registry
uses: docker/login-action@v3
@ -55,7 +55,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Login to GitHub package registry
uses: azure/docker-login@v1

View File

@ -57,7 +57,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Login to GitHub package registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # v3.1.0

View File

@ -83,7 +83,7 @@ jobs:
- uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2

View File

@ -31,7 +31,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@db19848a5fa7950289d3668fb053140cf3028d43 # v3.3.2

View File

@ -47,7 +47,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Login to GitHub package registry
if: inputs.publish

View File

@ -39,7 +39,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Increase gradle daemon heap size
run: |

View File

@ -38,7 +38,7 @@ jobs:
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: temurin
java-version: 17.0.6
java-version: 21
- name: Increase gradle daemon heap size
run: |

View File

@ -8,7 +8,7 @@ and discuss your ideas or propose the changes you wish to make.
## Building
This project requires Java 17 to build and run tests. Newer JDK's may work, but this version is used in CI.
This project requires Java 21 to build and run tests. Newer JDK's may work, but this version is used in CI.
Some instrumentations and tests may put constraints on which java versions they support.
See [Running the tests](./docs/contributing/running-tests.md) for more details.
@ -22,7 +22,7 @@ the Sonatype OSS snapshots repository at `https://oss.sonatype.org/content/repos
### Building from source
Build using Java 17:
Build using Java 21:
```bash
java -version

View File

@ -10,6 +10,7 @@ import org.gradle.api.provider.Property
abstract class OtelJavaExtension {
abstract val minJavaVersionSupported: Property<JavaVersion>
abstract val maxJavaVersionSupported: Property<JavaVersion>
abstract val maxJavaVersionForTests: Property<JavaVersion>

View File

@ -27,12 +27,15 @@ afterEvaluate {
}
// Version to use to compile code and run tests.
val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_17
val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_21
java {
toolchain {
languageVersion.set(
otelJava.minJavaVersionSupported.map { JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), DEFAULT_JAVA_VERSION.majorVersion.toInt())) }
otelJava.minJavaVersionSupported.map {
val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt()
JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), defaultJavaVersion))
}
)
}
@ -69,11 +72,18 @@ tasks.withType<JavaCompile>().configureEach {
"-Xlint:-processing",
// We suppress the "options" warning because it prevents compilation on modern JDKs
"-Xlint:-options",
// jdk21 generates more serial warnings than previous versions
"-Xlint:-serial",
// Fail build on any warning
"-Werror"
)
)
val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt()
if (Math.max(otelJava.minJavaVersionSupported.get().majorVersion.toInt(), defaultJavaVersion) >= 21) {
// new warning in jdk21
compilerArgs.add("-Xlint:-this-escape")
}
}
encoding = "UTF-8"
@ -81,6 +91,11 @@ tasks.withType<JavaCompile>().configureEach {
if (name.contains("Test")) {
// serialVersionUID is basically guaranteed to be useless in tests
compilerArgs.add("-Xlint:-serial")
// when code is compiled with jdk 21 and executed with jdk 8, the -parameters flag is needed to avoid
// java.lang.reflect.MalformedParametersException: Invalid parameter name ""
// when junit calls java.lang.reflect.Executable.getParameters() on the constructor of a
// non-static nested test class
compilerArgs.add("-parameters")
}
}
}

View File

@ -36,6 +36,8 @@ tasks {
"--add-exports",
"jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED",
"--add-exports",
"jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED",

View File

@ -2,6 +2,16 @@ plugins {
id("otel.java-conventions")
}
tasks {
compileJava {
// when code is compiled with jdk 21 and executed with jdk 8 -parameters flag is needed to avoid
// java.lang.reflect.MalformedParametersException: Invalid parameter name ""
// when junit calls java.lang.reflect.Executable.getParameters() on the constructor of a
// non-static nested test class
options.compilerArgs.add("-parameters")
}
}
dependencies {
api(project(":testing-common"))

View File

@ -31,7 +31,7 @@ class SanitizationTest {
when(exchange.getIn()).thenReturn(message);
String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(actualSanitized, expected);
assertEquals(expected, actualSanitized);
}
@ParameterizedTest
@ -45,7 +45,7 @@ class SanitizationTest {
when(exchange.getIn()).thenReturn(message);
String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(actualSanitized, expected);
assertEquals(expected, actualSanitized);
}
@ParameterizedTest
@ -60,7 +60,7 @@ class SanitizationTest {
when(exchange.getIn()).thenReturn(message);
String actualSanitized = decorator.getStatement(exchange, null);
assertEquals(actualSanitized, expected);
assertEquals(expected, actualSanitized);
}
static class SqlArgs implements ArgumentsProvider {

View File

@ -28,6 +28,13 @@ muzzle {
}
}
if (findProperty("testLatestDeps") as Boolean) {
// when running on jdk 21 Elasticsearch53SpringRepositoryTest occasionally fails with timeout
otelJava {
maxJavaVersionSupported.set(JavaVersion.VERSION_17)
}
}
dependencies {
compileOnly("org.elasticsearch.client:transport:5.3.0") {
isTransitive = false

View File

@ -7,8 +7,6 @@ package io.opentelemetry.javaagent.instrumentation.executors;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -26,8 +24,6 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.extension.RegisterExtension;
abstract class ExecutorInstrumentationTest<T extends ExecutorService>
@ -51,24 +47,6 @@ abstract class ExecutorInstrumentationTest<T extends ExecutorService>
}
}
@EnabledForJreRange(min = JRE.JAVA_21)
static class VirtualThreadExecutorTest extends ExecutorInstrumentationTest<ExecutorService> {
VirtualThreadExecutorTest() {
super(newVirtualThreadPerTaskExecutor());
}
private static ExecutorService newVirtualThreadPerTaskExecutor() {
Method newVirtualThreadPerTaskExecutor;
try {
newVirtualThreadPerTaskExecutor =
Executors.class.getMethod("newVirtualThreadPerTaskExecutor");
return (ExecutorService) newVirtualThreadPerTaskExecutor.invoke(null);
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
throw new IllegalStateException("Should not happen on Java 21+", e);
}
}
}
static class WorkStealingPoolTest extends ExecutorInstrumentationTest<ExecutorService> {
public WorkStealingPoolTest() {
super(Executors.newWorkStealingPool(2));

View File

@ -0,0 +1,20 @@
plugins {
id("otel.javaagent-testing")
}
dependencies {
testInstrumentation(project(":instrumentation:executors:javaagent"))
testCompileOnly(project(":instrumentation:executors:bootstrap"))
testImplementation(project(":instrumentation:executors:testing"))
}
otelJava {
minJavaVersionSupported.set(JavaVersion.VERSION_21)
}
tasks.withType<Test>().configureEach {
// needed for VirtualThreadTest
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
}

View File

@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.executors;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.junit.jupiter.api.extension.RegisterExtension;
class VirtualThreadExecutorTest
extends AbstractExecutorServiceTest<ExecutorService, JavaAsyncChild> {
@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
VirtualThreadExecutorTest() {
super(Executors.newVirtualThreadPerTaskExecutor(), testing);
}
@Override
protected JavaAsyncChild newTask(boolean doTraceableWork, boolean blockThread) {
return new JavaAsyncChild(doTraceableWork, blockThread);
}
}

View File

@ -12,21 +12,13 @@ import java.lang.reflect.Method;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledForJreRange;
import org.junit.jupiter.api.condition.JRE;
@EnabledForJreRange(min = JRE.JAVA_21)
class VirtualThreadTest {
@Test
void testDisableContextPropagation() throws Exception {
TestRunnable testRunnable = new TestRunnable();
// Thread.ofVirtual().start(testRunnable);
Method ofVirtualMethod = Thread.class.getMethod("ofVirtual");
Object virtualThreadBuilder = ofVirtualMethod.invoke(null);
Method startVirtualThread =
Class.forName("java.lang.Thread$Builder").getMethod("start", Runnable.class);
Thread thread = (Thread) startVirtualThread.invoke(virtualThreadBuilder, testRunnable);
Thread thread = Thread.ofVirtual().start(testRunnable);
thread.join();
assertThat(testRunnable.error).isNull();

View File

@ -11,6 +11,7 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.atomic.AtomicBoolean;
@SuppressWarnings("serial")
final class JavaAsyncChild extends ForkJoinTask<Object> implements TestTask {
private static final Tracer tracer = GlobalOpenTelemetry.getTracer("test");

View File

@ -18,6 +18,10 @@ muzzle {
}
}
otelJava {
maxJavaVersionSupported.set(JavaVersion.VERSION_17)
}
val grailsVersion = "3.0.6" // first version that the tests pass on
val springBootVersion = "1.2.5.RELEASE"

View File

@ -28,6 +28,10 @@ muzzle {
}
}
otelJava {
maxJavaVersionSupported.set(JavaVersion.VERSION_17)
}
dependencies {
compileOnly("dev.zio:zio_$scalaVersion:$zioVersion")

View File

@ -294,13 +294,19 @@ public final class ReferenceMatcher {
return null;
}
TypeDescription superType = null;
if (typeOnClasspath.getSuperClass() != null) {
MethodDescription.InDefinedShape methodOnSupertype =
findMethod(methodRef, typeOnClasspath.getSuperClass().asErasure());
superType = typeOnClasspath.getSuperClass().asErasure();
} else if (!"java.lang.Object".equals(typeOnClasspath.getName())) {
superType = TypeDescription.ForLoadedType.of(Object.class);
}
if (superType != null) {
MethodDescription.InDefinedShape methodOnSupertype = findMethod(methodRef, superType);
if (methodOnSupertype != null) {
return methodOnSupertype;
}
}
for (TypeDescription.Generic interfaceType : typeOnClasspath.getInterfaces()) {
MethodDescription.InDefinedShape methodOnSupertype =
findMethod(methodRef, interfaceType.asErasure());

View File

@ -227,6 +227,7 @@ include(":instrumentation:elasticsearch:elasticsearch-transport-common:javaagent
include(":instrumentation:elasticsearch:elasticsearch-transport-common:testing")
include(":instrumentation:executors:bootstrap")
include(":instrumentation:executors:javaagent")
include(":instrumentation:executors:jdk21-testing")
include(":instrumentation:executors:testing")
include(":instrumentation:external-annotations:javaagent")
include(":instrumentation:external-annotations:javaagent-unit-tests")