From 9126b8e3e469e956a1e55dde50d6e1ecb828b707 Mon Sep 17 00:00:00 2001 From: Kess Plasmeier Date: Thu, 29 May 2025 11:07:32 -0700 Subject: [PATCH 1/3] fix: guard against null version and change property name to avoid conflicts --- .../com/amazonaws/encryptionsdk/internal/VersionInfo.java | 7 ++++++- src/main/resources/project.properties | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java b/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java index 85b66602e..268547f07 100644 --- a/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java +++ b/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java @@ -14,6 +14,7 @@ package com.amazonaws.encryptionsdk.internal; import java.io.IOException; +import java.util.Objects; import java.util.Properties; /** This class specifies the versioning system for the AWS KMS encryption client. */ @@ -44,7 +45,11 @@ public static String versionNumber() { final Properties properties = new Properties(); final ClassLoader loader = VersionInfo.class.getClassLoader(); properties.load(loader.getResourceAsStream("project.properties")); - return properties.getProperty("version"); + String maybeVersion = properties.getProperty("esdkVersion"); + // In some cases, another dependency MAY also define a project.properties file, + // which MAY be loaded before the ESDK's. In this case, the version property + // MAY NOT exist, which causes an NPE later on. + return Objects.requireNonNullElse(maybeVersion, UNKNOWN_VERSION); } catch (final IOException ex) { return UNKNOWN_VERSION; } diff --git a/src/main/resources/project.properties b/src/main/resources/project.properties index defbd4820..66a409a9d 100644 --- a/src/main/resources/project.properties +++ b/src/main/resources/project.properties @@ -1 +1 @@ -version=${project.version} +esdkVersion=${project.version} From b739d3c9d4dad6e431effd869f82f90b7c9c4a22 Mon Sep 17 00:00:00 2001 From: Kess Plasmeier Date: Thu, 29 May 2025 11:15:32 -0700 Subject: [PATCH 2/3] java 8 compat --- .../com/amazonaws/encryptionsdk/internal/VersionInfo.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java b/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java index 268547f07..9dc2bd212 100644 --- a/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java +++ b/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java @@ -49,7 +49,11 @@ public static String versionNumber() { // In some cases, another dependency MAY also define a project.properties file, // which MAY be loaded before the ESDK's. In this case, the version property // MAY NOT exist, which causes an NPE later on. - return Objects.requireNonNullElse(maybeVersion, UNKNOWN_VERSION); + if (maybeVersion == null) { + return UNKNOWN_VERSION; + } else { + return maybeVersion; + } } catch (final IOException ex) { return UNKNOWN_VERSION; } From e647bba76cae76ed9f4250494ab225ec4e45c7c2 Mon Sep 17 00:00:00 2001 From: Kess Plasmeier Date: Fri, 30 May 2025 11:18:47 -0700 Subject: [PATCH 3/3] pick the ESDK properties file specifically from URL enumeration --- .../encryptionsdk/internal/VersionInfo.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java b/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java index 9dc2bd212..09408c58f 100644 --- a/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java +++ b/src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java @@ -14,7 +14,8 @@ package com.amazonaws.encryptionsdk.internal; import java.io.IOException; -import java.util.Objects; +import java.net.URL; +import java.util.Enumeration; import java.util.Properties; /** This class specifies the versioning system for the AWS KMS encryption client. */ @@ -44,12 +45,23 @@ public static String versionNumber() { try { final Properties properties = new Properties(); final ClassLoader loader = VersionInfo.class.getClassLoader(); - properties.load(loader.getResourceAsStream("project.properties")); + // Other JARs on the classpath may also define project.properties + // Enumerate through and find the one for the ESDK + Enumeration urls = loader.getResources("project.properties"); + if (urls == null) { + return UNKNOWN_VERSION; + } + while (urls.hasMoreElements()) { + URL thisURL = urls.nextElement(); + if (thisURL.getPath().contains("aws-encryption-sdk-java")) { + properties.load(thisURL.openStream()); + break; + } + } String maybeVersion = properties.getProperty("esdkVersion"); - // In some cases, another dependency MAY also define a project.properties file, - // which MAY be loaded before the ESDK's. In this case, the version property - // MAY NOT exist, which causes an NPE later on. if (maybeVersion == null) { + // This should never happen in practice, + // but is included for robustness. return UNKNOWN_VERSION; } else { return maybeVersion;