Skip to content

Commit 313caa7

Browse files
authored
fix: guard against null version and change property name to avoid conflicts (#2116)
* pick the ESDK properties file specifically from URL enumeration
1 parent 08cf1a3 commit 313caa7

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/main/java/com/amazonaws/encryptionsdk/internal/VersionInfo.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package com.amazonaws.encryptionsdk.internal;
1515

1616
import java.io.IOException;
17+
import java.net.URL;
18+
import java.util.Enumeration;
1719
import java.util.Properties;
1820

1921
/** This class specifies the versioning system for the AWS KMS encryption client. */
@@ -43,8 +45,27 @@ public static String versionNumber() {
4345
try {
4446
final Properties properties = new Properties();
4547
final ClassLoader loader = VersionInfo.class.getClassLoader();
46-
properties.load(loader.getResourceAsStream("project.properties"));
47-
return properties.getProperty("version");
48+
// Other JARs on the classpath may also define project.properties
49+
// Enumerate through and find the one for the ESDK
50+
Enumeration<URL> urls = loader.getResources("project.properties");
51+
if (urls == null) {
52+
return UNKNOWN_VERSION;
53+
}
54+
while (urls.hasMoreElements()) {
55+
URL thisURL = urls.nextElement();
56+
if (thisURL.getPath().contains("aws-encryption-sdk-java")) {
57+
properties.load(thisURL.openStream());
58+
break;
59+
}
60+
}
61+
String maybeVersion = properties.getProperty("esdkVersion");
62+
if (maybeVersion == null) {
63+
// This should never happen in practice,
64+
// but is included for robustness.
65+
return UNKNOWN_VERSION;
66+
} else {
67+
return maybeVersion;
68+
}
4869
} catch (final IOException ex) {
4970
return UNKNOWN_VERSION;
5071
}

src/main/resources/project.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=${project.version}
1+
esdkVersion=${project.version}

0 commit comments

Comments
 (0)