Skip to content

Commit 5223ff6

Browse files
[MNG-8178] Fall back to system properties for missing profile activation 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 <[email protected]>
1 parent d5e8e93 commit 5223ff6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

maven-model-builder/src/main/java/org/apache/maven/model/profile/activation/OperatingSystemProfileActivator.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ public boolean isActive(Profile profile, ProfileActivationContext context, Model
5858

5959
boolean active = ensureAtLeastOneNonNull(os);
6060

61-
String actualOsName = context.getSystemProperties().get("os.name").toLowerCase(Locale.ENGLISH);
62-
String actualOsArch = context.getSystemProperties().get("os.arch").toLowerCase(Locale.ENGLISH);
63-
String actualOsVersion = context.getSystemProperties().get("os.version").toLowerCase(Locale.ENGLISH);
61+
String actualOsName = context.getSystemProperties()
62+
.getOrDefault("os.name", Os.OS_NAME)
63+
.toLowerCase(Locale.ENGLISH);
64+
String actualOsArch = context.getSystemProperties()
65+
.getOrDefault("os.arch", Os.OS_ARCH)
66+
.toLowerCase(Locale.ENGLISH);
67+
String actualOsVersion = context.getSystemProperties()
68+
.getOrDefault("os.version", Os.OS_VERSION)
69+
.toLowerCase(Locale.ENGLISH);
6470

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

0 commit comments

Comments
 (0)