Skip to content

Commit

Permalink
Fix JRUBY-6514
Browse files Browse the repository at this point in the history
java.lang.NullPointerException when using ScriptingCotainer from an Applet

Properties retrieved in a restricted environment may be null. We
must handle that case and not blindly try to getBytes().
  • Loading branch information
headius authored and dekellum committed Aug 3, 2012
1 parent b8d0ca6 commit 8115b8c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/org/jruby/util/OSEnvironment.java
Expand Up @@ -82,8 +82,11 @@ private static Map getAsMapOfRubyStrings(Ruby runtime, Set<Map.Entry<Object, Obj

// On Windows, entrySet doesn't have corresponding keys for these
if (Platform.IS_WINDOWS) {
addRubyKeyValuePair(runtime, envs, "HOME", SafePropertyAccessor.getProperty("user.home"), encoding);
addRubyKeyValuePair(runtime, envs, "USER", SafePropertyAccessor.getProperty("user.name"), encoding);
// these may be null when in a restricted environment (JRUBY-6514)
String home = SafePropertyAccessor.getProperty("user.home");
String user = SafePropertyAccessor.getProperty("user.name");
addRubyKeyValuePair(runtime, envs, "HOME", home == null ? "/" : home, encoding);
addRubyKeyValuePair(runtime, envs, "USER", user == null ? "" : user, encoding);
}

for (Map.Entry<Object, Object> entry : entrySet) {
Expand Down

0 comments on commit 8115b8c

Please sign in to comment.