Skip to content

Commit 9f49959

Browse files
hdurixtchlyah
authored andcommitted
Prevent NullPointerException when getting OS name (#2)
* Prevent NullPointerException when getting OS name In some environments (ie: with OpenShift), username retrieved by the system is `null`. If this is the case, it should return "unknown" (same as with unknown OS name).
1 parent dbec83e commit 9f49959

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • src/main/java/com/github/couchmove/utils

src/main/java/com/github/couchmove/utils/Utils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ private static String initializeUserName() {
4545
Class<?> c = Class.forName(className);
4646
Method method = c.getDeclaredMethod(methodName);
4747
Object o = c.newInstance();
48-
return method.invoke(o).toString();
48+
Object name = method.invoke(o);
49+
if (name != null) {
50+
return name.toString();
51+
}
4952
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
5053
logger.error("Unable to get actual user name", e);
5154
}

0 commit comments

Comments
 (0)