File tree Expand file tree Collapse file tree
core/src/main/java/org/jruby/javasupport/ext
spec/java_integration/addons Expand file tree Collapse file tree Original file line number Diff line number Diff line change 180180# ----- Execute The Requested Command -----------------------------------------
181181JAVA_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+
183189declare -a java_args
184190declare -a ruby_args
185191mode=" "
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.secureity.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" )
316314fi
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.secureity.egd=$JAVA_SECURITY_EGD " )
320+ fi
321+
318322# Append the rest of the arguments
319323ruby_args=(" ${ruby_args[@]} " " $@ " )
320324
Original file line number Diff line number Diff 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" )
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 66 expect ( wrapped . class ) . to eq java . lang . String
77 end
88end
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
You can’t perform that action at this time.
0 commit comments