Skip to content

Commit 54be51f

Browse files
committed
convert to java
1 parent b87e251 commit 54be51f

File tree

4 files changed

+42
-24
lines changed

4 files changed

+42
-24
lines changed

javaagent-tooling/javaagent-tooling-java9/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,12 @@ tasks {
2929
compilerArgs.add("-Xlint:none")
3030
}
3131
}
32+
compileTestJava {
33+
with(options) {
34+
// Because this module targets Java 9, we trigger this compiler bug which was fixed but not
35+
// backported to Java 9 compilation.
36+
// https://bugs.openjdk.java.net/browse/JDK-8209058
37+
compilerArgs.add("-Xlint:none")
38+
}
39+
}
3240
}

javaagent-tooling/javaagent-tooling-java9/src/main/java/io/opentelemetry/javaagent/tooling/UnsafeInitializer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ static void initialize(Instrumentation instrumentation, ClassLoader classLoader)
2222
initialize(instrumentation, classLoader, true);
2323
}
2424

25-
private static void initialize(
25+
// visible for testing
26+
static void initialize(
2627
Instrumentation instrumentation, ClassLoader classLoader, boolean testUnsafePresent) {
2728
Class<?> unsafeClass;
2829
try {

javaagent-tooling/javaagent-tooling-java9/src/test/groovy/UnsafeTest.groovy

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.tooling;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
import io.opentelemetry.javaagent.bootstrap.AgentClassLoader;
11+
import java.io.File;
12+
import java.net.URL;
13+
import net.bytebuddy.agent.ByteBuddyAgent;
14+
import org.junit.jupiter.api.Test;
15+
16+
class UnsafeTest {
17+
18+
@Test
19+
void testGenerateSunMiscUnsafe() throws Exception {
20+
ByteBuddyAgent.install();
21+
URL testJarLocation =
22+
AgentClassLoader.class.getProtectionDomain().getCodeSource().getLocation();
23+
24+
try (AgentClassLoader loader = new AgentClassLoader(new File(testJarLocation.toURI()))) {
25+
UnsafeInitializer.initialize(ByteBuddyAgent.getInstrumentation(), loader, false);
26+
27+
Class<?> unsafeClass = loader.loadClass("sun.misc.Unsafe");
28+
29+
assertThat(unsafeClass.getClassLoader()).isEqualTo(loader);
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)