Skip to content

Commit a09f6a1

Browse files
committed
Load buildinfo from multiple classloaders
1 parent f060daf commit a09f6a1

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

proc/sysinfo/src/main/java/org/neo4j/gds/BuildInfoProperties.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.UncheckedIOException;
2727
import java.nio.charset.StandardCharsets;
2828
import java.util.Properties;
29+
import java.util.stream.Stream;
2930

3031
@ValueClass
3132
public abstract class BuildInfoProperties {
@@ -81,18 +82,23 @@ private static BuildInfoProperties infoProperties() throws IOException {
8182
private static final Object INFO_PROPERTIES = loadProperties();
8283

8384
private static Object loadProperties() {
84-
var properties = new Properties();
85-
var classLoader = Thread.currentThread().getContextClassLoader();
86-
try (var infoStream = classLoader.getResourceAsStream(INFO_FILE)) {
87-
if (infoStream != null) {
88-
try (var infoReader = new InputStreamReader(infoStream, StandardCharsets.UTF_8)) {
89-
properties.load(infoReader);
85+
return Stream.of(
86+
Thread.currentThread().getContextClassLoader(),
87+
BuildInfoProperties.class.getClassLoader()
88+
).flatMap(cl -> Stream.ofNullable(cl.getResourceAsStream(INFO_FILE)))
89+
.findFirst()
90+
.map(infoStream -> {
91+
try (infoStream) {
92+
try (var infoReader = new InputStreamReader(infoStream, StandardCharsets.UTF_8)) {
93+
var properties = new Properties();
94+
properties.load(infoReader);
95+
return from(properties);
96+
}
97+
} catch (IOException exception) {
98+
return exception;
9099
}
91-
}
92-
} catch (IOException exception) {
93-
return exception;
94-
}
95-
return from(properties);
100+
})
101+
.orElseGet(() -> new IOException("Could not find " + INFO_FILE));
96102
}
97103
}
98104
}

0 commit comments

Comments
 (0)