Skip to content

Commit f21c6c9

Browse files
committed
[chore] Remove use of deprecated JRuby 9.3 cat19 function
catWithCodeRange will not work with JRuby < 9.4.7.0 (Apr 2024), but as this patch release is 18 months old, it's reasonable to expect patching.
1 parent 6298803 commit f21c6c9

File tree

1 file changed

+1
-28
lines changed

1 file changed

+1
-28
lines changed

src/main/java/org/jruby/rack/ext/Input.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
import java.io.ByteArrayOutputStream;
1111
import java.io.IOException;
1212
import java.io.InputStream;
13-
import java.lang.invoke.MethodHandle;
14-
import java.lang.invoke.MethodHandles;
15-
import java.lang.invoke.MethodType;
1613
import java.lang.reflect.InvocationTargetException;
1714
import java.lang.reflect.Method;
1815

@@ -27,7 +24,6 @@
2724
import org.jruby.rack.servlet.RewindableInputStream;
2825
import org.jruby.rack.util.ExceptionUtils;
2926
import org.jruby.runtime.Block;
30-
import org.jruby.runtime.Helpers;
3127
import org.jruby.runtime.ObjectAllocator;
3228
import org.jruby.runtime.ThreadContext;
3329
import org.jruby.runtime.builtin.IRubyObject;
@@ -42,24 +38,6 @@
4238
*/
4339
@SuppressWarnings("serial")
4440
public class Input extends RubyObject {
45-
private static final MethodHandle CONCAT_WITH_CODERANGE;
46-
47-
static {
48-
// set up coderange-aware concat that works with the new catWithCodeRange as well as earlier JRuby without it.
49-
// TODO: remove and replace with direct call once 9.3 is fully unsupported
50-
MethodHandle catWithCR = null;
51-
MethodHandles.Lookup lookup = MethodHandles.lookup();
52-
try {
53-
catWithCR = lookup.findVirtual(RubyString.class, "catWithCodeRange", MethodType.methodType(int.class, ByteList.class, int.class));
54-
} catch (NoSuchMethodException | IllegalAccessException e) {
55-
try {
56-
catWithCR = lookup.findVirtual(RubyString.class, "cat19", MethodType.methodType(int.class, ByteList.class, int.class));
57-
} catch (Exception t) {
58-
Helpers.throwException(t);
59-
}
60-
}
61-
CONCAT_WITH_CODERANGE = catWithCR;
62-
}
6341

6442
static final ObjectAllocator ALLOCATOR = Input::new;
6543

@@ -166,12 +144,7 @@ public IRubyObject read(final ThreadContext context, final IRubyObject[] args) {
166144
if ( bytes != null ) {
167145
if ( buffer != null ) {
168146
buffer.clear();
169-
try {
170-
int unused = (int) CONCAT_WITH_CODERANGE.invokeExact(buffer, new ByteList(bytes, false), StringSupport.CR_UNKNOWN);
171-
} catch (Throwable t) {
172-
Helpers.throwException(t);
173-
}
174-
147+
buffer.catWithCodeRange(new ByteList(bytes, false), StringSupport.CR_UNKNOWN);
175148
return buffer;
176149
}
177150
return context.runtime.newString(new ByteList(bytes, false));

0 commit comments

Comments
 (0)