Skip to content

Commit 25cdac8

Browse files
committed
Optional
1 parent fc0a49b commit 25cdac8

File tree

1 file changed

+6
-5
lines changed
  • sdk/trace-shaded-deps/src/main/java/io/opentelemetry/sdk/trace/internal

1 file changed

+6
-5
lines changed

sdk/trace-shaded-deps/src/main/java/io/opentelemetry/sdk/trace/internal/JcTools.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package io.opentelemetry.sdk.trace.internal;
77

88
import java.util.Objects;
9+
import java.util.Optional;
910
import java.util.Queue;
1011
import java.util.concurrent.atomic.AtomicBoolean;
1112
import java.util.function.Consumer;
@@ -69,22 +70,22 @@ public static <T> int drain(Queue<T> queue, int limit, Consumer<T> consumer) {
6970
}
7071

7172
private static boolean proactivelyAvoidUnsafe() {
72-
double javaVersion = getJavaVersion();
73+
Optional<Double> javaVersion = getJavaVersion();
7374
// Avoid Unsafe on Java 23+ due to JEP-498 deprecation warnings:
7475
// "WARNING: A terminally deprecated method in sun.misc.Unsafe has been called"
75-
return javaVersion >= 23 || javaVersion == -1;
76+
return javaVersion.map(version -> version >= 23).orElse(true);
7677
}
7778

78-
private static double getJavaVersion() {
79+
private static Optional<Double> getJavaVersion() {
7980
String specVersion = System.getProperty("java.specification.version");
8081
if (specVersion != null) {
8182
try {
82-
return Double.parseDouble(specVersion);
83+
return Optional.of(Double.parseDouble(specVersion));
8384
} catch (NumberFormatException exception) {
8485
// ignore
8586
}
8687
}
87-
return -1;
88+
return Optional.empty();
8889
}
8990

9091
private JcTools() {}

0 commit comments

Comments
 (0)