Index: test/test_yaml.rb
===================================================================
--- test/test_yaml.rb	(revision 4889)
+++ test/test_yaml.rb	(working copy)
@@ -30,6 +30,15 @@
     assert_nothing_raised { YAML.dump(@obj) }
   end
 
+  def test_yaml_load_with_bad_type_raises_typeerror
+    [[], {}].each do |not_an_IO_object|
+      err = assert_raise(TypeError) do
+        YAML.load(not_an_IO_object)
+      end
+      assert_match("instance of IO needed", err.message)
+    end
+  end
+
 	#
 	# Convert between YAML and the object to verify correct parsing and
 	# emitting
Index: src/org/jruby/RubyYAML.java
===================================================================
--- src/org/jruby/RubyYAML.java	(revision 4889)
+++ src/org/jruby/RubyYAML.java	(working copy)
@@ -209,7 +209,7 @@
     }
 
     public static IRubyObject load(IRubyObject self, IRubyObject arg) {
-        IRubyObject io = arg;
+        IRubyObject io = check_yaml_port(arg);
         Scanner scn = null;
         if(io instanceof RubyString) {
             scn = new ScannerImpl(((RubyString)io).getByteList());
@@ -249,7 +249,7 @@
 
     public static IRubyObject load_documents(IRubyObject self, IRubyObject arg, Block block) {
         ThreadContext context = self.getRuntime().getCurrentContext();
-        IRubyObject io = arg;
+        IRubyObject io = check_yaml_port(arg);
         Scanner scn = null;
         if(io instanceof RubyString) {
             scn = new ScannerImpl(((RubyString)io).getByteList());
@@ -300,6 +300,23 @@
         return self.getRuntime().getNil();
     }
 
+    // prepares IO port type for load (ported from ext/syck/rubyext.c)
+    private static IRubyObject check_yaml_port(IRubyObject port) {
+        if (port instanceof RubyString) {
+            // OK
+        }
+        else if (port.respondsTo("read")) {
+            if (port.respondsTo("binmode")) {
+                ThreadContext context = port.getRuntime().getCurrentContext();
+                port.callMethod(context, "binmode");
+            }
+        }
+        else {
+            throw port.getRuntime().newTypeError("instance of IO needed");
+        }
+        return port;
+    }
+
     public static IRubyObject hash_to_yaml_node(IRubyObject self, IRubyObject arg) {
         ThreadContext context = self.getRuntime().getCurrentContext();
         return arg.callMethod(context,"map", new IRubyObject[]{self.callMethod(context, "taguri"),self,self.callMethod(context, "to_yaml_style")});
