Skip to content

Commit 0edb58d

Browse files
committed
fix java version parsing
1 parent 72f7d62 commit 0edb58d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/runtimemetrics/Java8RuntimeMetricsProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Java8RuntimeMetricsProvider implements RuntimeMetricsProvider {
2323

2424
@Override
2525
public int minJavaVersion() {
26-
return 1;
26+
return 8;
2727
}
2828

2929
@Override

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/internal/instrumentation/runtimemetrics/RuntimeMetricsAutoConfiguration.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void handleApplicationReadyEvent(ApplicationReadyEvent event) {
4848
ConfigPropertiesBridge config =
4949
new ConfigPropertiesBridge(applicationContext.getBean(ConfigProperties.class));
5050

51-
double version = Double.parseDouble(System.getProperty("java.specification.version"));
51+
double version = javaVersion();
5252
Optional<RuntimeMetricsProvider> metricsProvider =
5353
applicationContext.getBeanProvider(RuntimeMetricsProvider.class).stream()
5454
.sorted(Comparator.comparing(RuntimeMetricsProvider::minJavaVersion).reversed())
@@ -61,4 +61,13 @@ public void handleApplicationReadyEvent(ApplicationReadyEvent event) {
6161
logger.debug("No runtime metrics instrumentation available for Java {}", version);
6262
}
6363
}
64+
65+
private int javaVersion() {
66+
try {
67+
return Integer.parseInt(System.getProperty("java.specification.version"));
68+
} catch (NumberFormatException nfe) {
69+
// The value of the java.specification.version property is 1.8 with a Java 8 runtime.
70+
return 8;
71+
}
72+
}
6473
}

0 commit comments

Comments
 (0)