When JRuby is setting up the global environment it sets the JAVA_ENV variable to the value of Java's System.properties. When there is a non String value the OSEnvironment code below will throw a ClassCastException.
private static Map getAsMapOfRubyStrings(Ruby runtime, Set<Map.Entry<Object, Object>> entrySet) {
Map envs = new HashMap();
Encoding encoding = runtime.getEncodingService().getLocaleEncoding();
// On Windows, entrySet doesn't have corresponding keys for these
if (Platform.IS_WINDOWS) {
// 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) {
// This will throw a ClassCastException if the value is not a String
String value = (String)entry.getValue();
String key = (String)entry.getKey();
addRubyKeyValuePair(runtime, envs, key, value, encoding);
}
return envs;
}
Though Properties should be all String values, since they are subclassed from java.util.Hashtable the put() method can add a non String object. From the Properties documentation:
"Because Properties inherits from Hashtable, the put and putAll methods can be applied to a Properties object. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are not Strings. The setProperty method should be used instead. If the store or save method is called on a "compromised" Properties object that contains a non-String key or value, the call will fail. Similarly, the call to the propertyNames or list method will fail if it is called on a "compromised" Properties object that contains a non-String key."
When JRuby is setting up the global environment it sets the JAVA_ENV variable to the value of Java's System.properties. When there is a non String value the OSEnvironment code below will throw a ClassCastException.
Though
Propertiesshould be allStringvalues, since they are subclassed fromjava.util.Hashtabletheput()method can add a nonStringobject. From thePropertiesdocumentation:"Because
Propertiesinherits fromHashtable, theputandputAllmethods can be applied to aPropertiesobject. Their use is strongly discouraged as they allow the caller to insert entries whose keys or values are notStrings. ThesetPropertymethod should be used instead. If the store or save method is called on a "compromised"Propertiesobject that contains a non-Stringkey or value, the call will fail. Similarly, the call to thepropertyNamesorlistmethod will fail if it is called on a "compromised"Propertiesobject that contains a non-Stringkey."