Skip to content

Commit 26dcd8a

Browse files
committedNov 11, 2017
Merge branch 'jruby-9.1'
2 parents 6576b3c + 65a004f commit 26dcd8a

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed
 

Diff for: ‎bin/jruby.bash

+14-10
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ fi
180180
# ----- Execute The Requested Command -----------------------------------------
181181
JAVA_ENCODING=""
182182

183+
if [ -e "/dev/urandom" ]; then
184+
# OpenJDK tries really hard to prevent you from using urandom.
185+
# See https://bugs.openjdk.java.net/browse/JDK-6202721
186+
JAVA_SECURITY_EGD="/dev/./urandom"
187+
fi
188+
183189
declare -a java_args
184190
declare -a ruby_args
185191
mode=""
@@ -219,21 +225,13 @@ do
219225
CP="$CP$CP_DELIMITER$2"
220226
CLASSPATH=""
221227
shift
222-
elif [ "${val:0:3}" = "-G:" ]; then # Graal options
223-
opt=${val:3}
224-
case $opt in
225-
+*)
226-
opt="${opt:1}=true" ;;
227-
-*)
228-
opt="${opt:1}=false" ;;
229-
esac
230-
echo "$1 is deprecated - use -J-Dgraal.$opt instead" >&2
231-
java_args=("${java_args[@]}" "-Dgraal.$opt")
232228
else
233229
if [ "${val:0:3}" = "-ea" ]; then
234230
VERIFY_JRUBY="yes"
235231
elif [ "${val:0:16}" = "-Dfile.encoding=" ]; then
236232
JAVA_ENCODING=$val
233+
elif [ "${val:0:20}" = "-Djava.security.egd=" ]; then
234+
JAVA_SECURITY_EGD=$val
237235
fi
238236
java_args=("${java_args[@]}" "${1:2}")
239237
fi
@@ -315,6 +313,12 @@ if [[ $darwin && -z "$JAVA_ENCODING" ]]; then
315313
java_args=("${java_args[@]}" "-Dfile.encoding=UTF-8")
316314
fi
317315

316+
# Force OpenJDK-based JVMs to use /dev/urandom for random number generation
317+
# See https://github.com/jruby/jruby/issues/4685 among others.
318+
if [[ -n "$JAVA_SECURITY_EGD" ]]; then
319+
java_args=("${java_args[@]}" "-Djava.security.egd=$JAVA_SECURITY_EGD")
320+
fi
321+
318322
# Append the rest of the arguments
319323
ruby_args=("${ruby_args[@]}" "$@")
320324

Diff for: ‎core/src/main/java/org/jruby/javasupport/ext/JavaLang.java

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public static void define(final Ruby runtime) {
7070
final RubyModule byteArray = Java.getProxyClass(runtime, new byte[0].getClass());
7171
byteArray.addMethod("ubyte_get", new UByteGet(byteArray));
7272
byteArray.addMethod("ubyte_set", new UByteSet(byteArray));
73+
74+
final RubyModule String = Java.getProxyClass(runtime, java.lang.String.class);
75+
String.defineAlias("to_str", "to_s");
76+
77+
final RubyModule Number = Java.getProxyClass(runtime, java.lang.Number.class);
78+
Number.defineAlias("to_int", "longValue");
79+
Number.defineAlias("to_f", "doubleValue");
7380
}
7481

7582
@JRubyModule(name = "Java::JavaLang::Iterable", include = "Enumerable")

Diff for: ‎spec/java_integration/addons/number_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require File.dirname(__FILE__) + "/../spec_helper"
2+
3+
describe "java.lang.Number subtypes" do
4+
describe "passed to numeric-coercing methods" do
5+
it "coerces successfully" do
6+
expect([42][0.to_java]).to eq 42
7+
8+
m = Mutex.new
9+
m.lock
10+
m.sleep(0.01.to_java)
11+
end
12+
end
13+
end

Diff for: ‎spec/java_integration/addons/string_spec.rb

+8
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@
66
expect(wrapped.class).to eq java.lang.String
77
end
88
end
9+
10+
describe "java.lang.String" do
11+
describe "passed to a String-coercing method" do
12+
it "coerces successfully" do
13+
expect("foo".concat("bar".to_java)).to eq "foobar"
14+
end
15+
end
16+
end

0 commit comments

Comments
 (0)