Index: src/org/jruby/RubyIO.java
===================================================================
--- src/org/jruby/RubyIO.java	(revision 8588)
+++ src/org/jruby/RubyIO.java	(working copy)
@@ -2042,6 +2042,10 @@
     public IRubyObject readpartial(ThreadContext context, IRubyObject[] args) {
         Ruby runtime = context.getRuntime();
 
+        if (args.length > 1) {
+          args[1].callMethod(context, "replace", RubyString.newString(runtime, ""));
+        }
+
         openFile.checkClosed(runtime);
 
         if(!(openFile.getMainStream() instanceof ChannelStream)) {
@@ -2053,7 +2057,14 @@
             if (maxLength < 0) {
                 throw runtime.newArgumentError("negative length " + maxLength + " given");
             }
-            ByteList buf = ((ChannelStream)openFile.getMainStream()).readpartial(RubyNumeric.fix2int(args[0]));
+
+            ChannelStream stream = (ChannelStream)openFile.getMainStream();
+            ByteList buf = stream.readpartial(RubyNumeric.fix2int(args[0]));
+
+            if (stream.feof() && (buf == null || buf.length() == 0)) {
+              throw runtime.newEOFError();
+            }
+                                                  
             IRubyObject strbuf = RubyString.newString(runtime, buf == null ? new ByteList(ByteList.NULL_ARRAY) : buf);
             if(args.length > 1) {
                 args[1].callMethod(context, "<<", strbuf);
@@ -2064,7 +2075,7 @@
         } catch (BadDescriptorException e) {
             throw runtime.newErrnoEBADFError();
         } catch (EOFException e) {
-            return runtime.getNil();
+            throw runtime.newEOFError(e.getMessage());
         } catch (IOException e) {
             throw runtime.newIOError(e.getMessage());
         }

