Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 2.3.0 incompatible with SpringBoot - KmsMasterKey class does not load #261

Closed
sparecycles opened this issue Jun 17, 2021 · 3 comments

Comments

@sparecycles
Copy link
Contributor

sparecycles commented Jun 17, 2021

Problem:

VersionInfo#loadUserAgent tries to load a version from a file, this fails catastrophically when this library is packed with the spring-boot-maven-plugin: the result of ClassLoader.getSystemResourceAsStream("project.properties") is null, triggering a NullPointerException which is not handled, which results in the following error for me.

java.lang.NoClassDefFoundError: Could not initialize class com.amazonaws.encryptionsdk.kms.KmsMasterKey

public final class KmsMasterKey extends MasterKey<KmsMasterKey> implements KmsMethods {
private static final String USER_AGENT = VersionInfo.loadUserAgent();

public static String loadUserAgent() {
try {
final Properties properties = new Properties();
properties.load(ClassLoader.getSystemResourceAsStream("project.properties"));
return USER_AGENT_PREFIX + properties.getProperty("version");
} catch (final IOException ex) {
return USER_AGENT_PREFIX + UNKNOWN_VERSION;
}
}

Works fine directly (IntelliJ run), but debugging the app within my docker-build clearly shows the issue:

is-null

throws-npe

application.jar packed with

      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>2.4.2</version> <!-- EDIT: also tested latest = 2.5.1 -->
      </plugin>

Solution(s):

  • Handle a null resource stream, and/or catch NullPointerExceptions here as well as IOExceptions.
  • Or simply hard-code the version directly in this file rather than delegating to a properties resource?
  • Use a classLoader from the same jar, e.g., the following works in my debugger:
properties.load(VersionInfo.class.getClassLoader().getResourceAsStream("project.properties"));
@dankirkd
Copy link

Any idea when this fix will be released?

@alex-chew
Copy link
Contributor

Sorry for the delay - the fix is now released as of v2.3.1: https://github.com/aws/aws-encryption-sdk-java/releases/tag/v2.3.1

@sparecycles
Copy link
Contributor Author

Fix confirmed working in deployment. Thanks @alex-chew !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants