File tree 4 files changed +42
-10
lines changed
core/src/main/java/org/jruby/javasupport/ext
spec/java_integration/addons
4 files changed +42
-10
lines changed Original file line number Diff line number Diff line change 180
180
# ----- Execute The Requested Command -----------------------------------------
181
181
JAVA_ENCODING=" "
182
182
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
+
183
189
declare -a java_args
184
190
declare -a ruby_args
185
191
mode=" "
219
225
CP=" $CP$CP_DELIMITER $2 "
220
226
CLASSPATH=" "
221
227
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 " )
232
228
else
233
229
if [ " ${val: 0: 3} " = " -ea" ]; then
234
230
VERIFY_JRUBY=" yes"
235
231
elif [ " ${val: 0: 16} " = " -Dfile.encoding=" ]; then
236
232
JAVA_ENCODING=$val
233
+ elif [ " ${val: 0: 20} " = " -Djava.security.egd=" ]; then
234
+ JAVA_SECURITY_EGD=$val
237
235
fi
238
236
java_args=(" ${java_args[@]} " " ${1: 2} " )
239
237
fi
@@ -315,6 +313,12 @@ if [[ $darwin && -z "$JAVA_ENCODING" ]]; then
315
313
java_args=(" ${java_args[@]} " " -Dfile.encoding=UTF-8" )
316
314
fi
317
315
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
+
318
322
# Append the rest of the arguments
319
323
ruby_args=(" ${ruby_args[@]} " " $@ " )
320
324
Original file line number Diff line number Diff line change @@ -70,6 +70,13 @@ public static void define(final Ruby runtime) {
70
70
final RubyModule byteArray = Java .getProxyClass (runtime , new byte [0 ].getClass ());
71
71
byteArray .addMethod ("ubyte_get" , new UByteGet (byteArray ));
72
72
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" );
73
80
}
74
81
75
82
@ 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 6
6
expect ( wrapped . class ) . to eq java . lang . String
7
7
end
8
8
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
You can’t perform that action at this time.
0 commit comments