Skip to content

Commit c14926f

Browse files
committed
Use proper type for checkEncoding
1 parent b50e756 commit c14926f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ext/java/org/jruby/ext/stringio/StringIO.java

+9-8
Original file line numberDiff line numberDiff line change
@@ -1640,13 +1640,13 @@ public IRubyObject write(ThreadContext context, IRubyObject[] args) {
16401640
cat = lookup.findVirtual(RubyString.class, "catWithCodeRange", MethodType.methodType(RubyString.class, RubyString.class));
16411641
modify = lookup.findVirtual(RubyString.class, "modifyAndClearCodeRange", MethodType.methodType(void.class));
16421642
substr = lookup.findVirtual(RubyString.class, "substrEnc", MethodType.methodType(IRubyObject.class, Ruby.class, int.class, int.class));
1643-
checkEncoding = lookup.findStatic(RubyEncoding.class, "checkEncoding", MethodType.methodType(void.class, ThreadContext.class, Encoding.class, CodeRangeable.class));
1643+
checkEncoding = lookup.findStatic(RubyEncoding.class, "checkEncoding", MethodType.methodType(Encoding.class, ThreadContext.class, Encoding.class, CodeRangeable.class));
16441644
} catch (NoSuchMethodException | IllegalAccessException ex) {
16451645
try {
16461646
cat = lookup.findVirtual(RubyString.class, "cat19", MethodType.methodType(RubyString.class, RubyString.class));
16471647
modify = lookup.findVirtual(RubyString.class, "modify19", MethodType.methodType(void.class));
16481648
substr = lookup.findVirtual(RubyString.class, "substr19", MethodType.methodType(IRubyObject.class, Ruby.class, int.class, int.class));
1649-
checkEncoding = lookup.findStatic(StringIO.class, "checkEncoding", MethodType.methodType(void.class, ThreadContext.class, Encoding.class, CodeRangeable.class));
1649+
checkEncoding = lookup.findStatic(StringIO.class, "checkEncoding", MethodType.methodType(Encoding.class, ThreadContext.class, Encoding.class, CodeRangeable.class));
16501650
} catch (NoSuchMethodException | IllegalAccessException ex2) {
16511651
throw new ExceptionInInitializerError(ex2);
16521652
}
@@ -1737,7 +1737,7 @@ private long stringIOWrite(ThreadContext context, Ruby runtime, IRubyObject arg)
17371737

17381738
private static void rb_enc_check(ThreadContext context, Encoding enc, CodeRangeable str) {
17391739
try {
1740-
CHECK_ENCODING.invokeExact(context, enc, str);
1740+
Encoding ignored = (Encoding) CHECK_ENCODING.invokeExact(context, enc, str);
17411741
} catch (Throwable t) {
17421742
Helpers.throwException(t);
17431743
}
@@ -1748,11 +1748,12 @@ private static void rb_enc_check(ThreadContext context, Encoding enc, CodeRangea
17481748
*
17491749
* See discussion in https://github.com/ruby/stringio/pull/116.
17501750
*/
1751-
private static void checkEncoding(ThreadContext context, Encoding enc, CodeRangeable str) {
1752-
CodeRangeable fakeCodeRangeable = new EncodingOnlyCodeRangeable(enc);
1753-
Encoding enc1 = StringSupport.areCompatible(fakeCodeRangeable, str);
1754-
if (enc1 == null) throw context.runtime.newEncodingCompatibilityError("incompatible character encodings: " +
1755-
enc1 + " and " + str.getByteList().getEncoding());
1751+
private static Encoding checkEncoding(ThreadContext context, Encoding encoding, CodeRangeable str) {
1752+
CodeRangeable fakeCodeRangeable = new EncodingOnlyCodeRangeable(encoding);
1753+
Encoding enc = StringSupport.areCompatible(fakeCodeRangeable, str);
1754+
if (enc == null) throw context.runtime.newEncodingCompatibilityError("incompatible character encodings: " +
1755+
enc + " and " + str.getByteList().getEncoding());
1756+
return enc;
17561757
}
17571758

17581759
private static class EncodingOnlyCodeRangeable implements CodeRangeable {

0 commit comments

Comments
 (0)