diff --git a/common/src/main/java/bisq/common/app/Version.java b/common/src/main/java/bisq/common/app/Version.java index 729f2003a4..c6345413e0 100644 --- a/common/src/main/java/bisq/common/app/Version.java +++ b/common/src/main/java/bisq/common/app/Version.java @@ -21,6 +21,8 @@ import java.net.URL; import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.jar.Attributes; import java.util.jar.Manifest; @@ -140,14 +142,15 @@ public class Version { '}'); } - public String readCommitHash() { + public static Optional findCommitHash() { try { - String pth = getClass().getResource(getClass().getSimpleName() + ".class").toString(); + String pth = Objects.requireNonNull(Version.class.getResource(Version.class.getSimpleName() + ".class")).toString(); String mnf = pth.substring(0, pth.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; Attributes attr = new Manifest(new URL(mnf).openStream()).getMainAttributes(); - return attr.getValue("Implementation-Version"); - } catch (Exception ignored) { } - return "unknown"; + return Optional.of(attr.getValue("Implementation-Version")); + } catch (Exception ignored) { + return Optional.empty(); + } } public static final byte COMPENSATION_REQUEST = (byte) 0x01; diff --git a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java index a8b6f4b7ec..bbd5652806 100644 --- a/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java +++ b/core/src/main/java/bisq/core/network/p2p/inventory/GetInventoryRequestHandler.java @@ -150,7 +150,7 @@ public class GetInventoryRequestHandler implements MessageListener { // node inventory.put(InventoryItem.version, Version.VERSION); - inventory.put(InventoryItem.commitHash, new Version().readCommitHash()); + Version.findCommitHash().ifPresent(commitHash -> inventory.put(InventoryItem.commitHash, commitHash)); inventory.put(InventoryItem.usedMemory, String.valueOf(Profiler.getUsedMemoryInBytes())); inventory.put(InventoryItem.jvmStartTime, String.valueOf(ManagementFactory.getRuntimeMXBean().getStartTime()));