Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -44,7 +45,15 @@ 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");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the real problem is in line 47: the class loader will load only the first resource matching the name project.properties. If some other JAR file on the classpath contains such a file and appears before this library on the classpath, it will be loaded instead of this library's project.properties file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this just prevents the program from crashing. I'm going to explore ways to load the specific project.properties file next.

// 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) {
return UNKNOWN_VERSION;
} else {
return maybeVersion;
}
} catch (final IOException ex) {
return UNKNOWN_VERSION;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/project.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=${project.version}
esdkVersion=${project.version}
Loading