Skip to content

Commit 8271101

Browse files
committed
fix
1 parent b67be58 commit 8271101

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/internal/ConfigPropertiesUtil.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,12 @@ private static boolean supportsDeclarativeConfig() {
4949
* Declarative Config.
5050
*/
5151
public static Optional<Boolean> getBoolean(String propertyName) {
52-
return getString(propertyName).map(Boolean::parseBoolean);
52+
Optional<String> string = getString(propertyName);
53+
// lambdas must not be used here in early initialization phase on early JDK8 versions
54+
if (string.isPresent()) {
55+
return Optional.ofNullable(Boolean.parseBoolean(string.get()));
56+
}
57+
return Optional.empty();
5358
}
5459

5560
/**
@@ -69,15 +74,16 @@ public static Optional<Boolean> getBoolean(OpenTelemetry openTelemetry, String..
6974
* variables.
7075
*/
7176
public static Optional<Integer> getInt(String propertyName) {
72-
return getString(propertyName)
73-
.flatMap(
74-
s -> {
75-
try {
76-
return Optional.of(Integer.parseInt(s));
77-
} catch (NumberFormatException ignored) {
78-
return Optional.empty();
79-
}
80-
});
77+
Optional<String> string = getString(propertyName);
78+
// lambdas must not be used here in early initialization phase on early JDK8 versions
79+
if (string.isPresent()) {
80+
try {
81+
return Optional.of(Integer.parseInt(string.get()));
82+
} catch (NumberFormatException ignored) {
83+
// ignored
84+
}
85+
}
86+
return Optional.empty();
8187
}
8288

8389
/**

0 commit comments

Comments
 (0)