Skip to content

Commit 3f90fe4

Browse files
authored
Allow seek when underlying string is frozen (#121)
Fixes #119. Adds a test for this expectation.
1 parent 3f56884 commit 3f90fe4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

Diff for: ext/java/org/jruby/ext/stringio/StringIO.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -1356,8 +1356,6 @@ public IRubyObject seek(ThreadContext context, IRubyObject arg0, IRubyObject arg
13561356
}
13571357

13581358
private RubyFixnum seekCommon(ThreadContext context, int argc, IRubyObject arg0, IRubyObject arg1) {
1359-
checkModifiable();
1360-
13611359
Ruby runtime = context.runtime;
13621360

13631361
IRubyObject whence = context.nil;
@@ -1367,10 +1365,10 @@ private RubyFixnum seekCommon(ThreadContext context, int argc, IRubyObject arg0,
13671365
whence = arg1;
13681366
}
13691367

1370-
checkOpen();
1371-
13721368
StringIOData ptr = this.getPtr();
13731369

1370+
checkOpen();
1371+
13741372
boolean locked = lock(context, ptr);
13751373
try {
13761374
switch (whence.isNil() ? 0 : RubyNumeric.num2int(whence)) {

Diff for: test/stringio/test_stringio.rb

+5
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ def test_seek
483483
f.close unless f.closed?
484484
end
485485

486+
def test_seek_frozen_string
487+
f = StringIO.new(-"1234")
488+
assert_equal(0, f.seek(1))
489+
end
490+
486491
def test_each_byte
487492
f = StringIO.new("1234")
488493
a = []

0 commit comments

Comments
 (0)