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)
@@ -187,7 +187,7 @@
 
     @JRubyMethod(name = "load", required = 1, module = true, visibility = Visibility.PRIVATE)
     public static IRubyObject load(IRubyObject self, IRubyObject arg) {
-        IRubyObject io = arg;
+        IRubyObject io = check_yaml_port(arg);
         Scanner scn = null;
         try {
             if(io instanceof RubyString) {
@@ -240,7 +240,7 @@
     @JRubyMethod(name = "load_documents", required = 1, frame = true, module = true, visibility = Visibility.PRIVATE)
     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;
         try {
             if(io instanceof RubyString) {
@@ -305,6 +305,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 class YAMLHashMethods {
         @JRubyMethod(name = "to_yaml_node", required = 1)
         public static IRubyObject hash_to_yaml_node(IRubyObject self, IRubyObject arg) {
