Skip to content

Commit

Permalink
[MNG-8178] Fall back to system properties for missing profile activat…
Browse files Browse the repository at this point in the history
…ion context properties (#1603)

A call to context.getSystemProperties() may yield empty an empty map, or
one missing the desired key, which makes a subsequent call of
toLowerCase fail with a NullPointerException.

Fall-back to using Os.OS_NAME and similar properties.

---------

Co-authored-by: Guillaume Nodet <gnodet@gmail.com>
  • Loading branch information
kohlschuetter and gnodet committed Jul 10, 2024
1 parent d5e8e93 commit 5223ff6
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ public boolean isActive(Profile profile, ProfileActivationContext context, Model

boolean active = ensureAtLeastOneNonNull(os);

String actualOsName = context.getSystemProperties().get("os.name").toLowerCase(Locale.ENGLISH);
String actualOsArch = context.getSystemProperties().get("os.arch").toLowerCase(Locale.ENGLISH);
String actualOsVersion = context.getSystemProperties().get("os.version").toLowerCase(Locale.ENGLISH);
String actualOsName = context.getSystemProperties()
.getOrDefault("os.name", Os.OS_NAME)
.toLowerCase(Locale.ENGLISH);
String actualOsArch = context.getSystemProperties()
.getOrDefault("os.arch", Os.OS_ARCH)
.toLowerCase(Locale.ENGLISH);
String actualOsVersion = context.getSystemProperties()
.getOrDefault("os.version", Os.OS_VERSION)
.toLowerCase(Locale.ENGLISH);

if (active && os.getFamily() != null) {
active = determineFamilyMatch(os.getFamily(), actualOsName);
Expand Down

0 comments on commit 5223ff6

Please sign in to comment.