Affects Version/s: None
Fix Version/s: Release 1.2
In clojure.java.io, IOFactory is extended to java.net.Sockets. The make-input-stream method is implemented correctly, but the make-output-stream method is missing. Actually, there is another key in the map named :output-stream. That is probably some old code lying around that didn't get refactored.
When evaluated, the following is thrown: java.lang.IllegalArgumentException: Cannot open <#<Socket Socket[addr=google.com/22.214.171.124,port=80,localport=55335]>> as an OutputStream. (NO_SOURCE_FILE:0)
Any host/port combination that is open will do. I chose Google's HTTP server as an arbitrary example of an open port.
An instance of java.io.BufferedWriter.
All versions of Clojure 1.2 since commit cd8fc7c11213fbe99355 "promote clojure.contrib.io to clojure.java.io (with api changes)" by Stuart Halloway.
I mentioned this on the Clojure mail list at the end of this thread: http://groups.google.com/group/clojure/browse_thread/thread/898f5dbe14057277/8fe69b1d2104f8b4?lnk=gst&q=code+review#8fe69b1d2104f8b4
I signed the CA and posted it in the middle of June, but my name has not appeared on the list of contributors yet. I take the liberty of demonstrating how simple the fix should be:
<pre>diff --git a/src/clj/clojure/java/io.clj b/src/clj/clojure/java/io.clj
index 4d6c551..0151482 100644
@@ -260,7 +260,7 @@
:make-input-stream (fn [^Socket x opts] (.getInputStream x))
- :output-stream (fn [^Socket x opts] (output-stream (.getOutputStream x) opt
+ :make-output-stream (fn [^Socket x opts] (.getOutputStream x))))</pre>
A simple test that demonstrates this bug would be to check that the result of clojure.java.io/writer returns a java.net.Writer. Preferably, there should be unit tests for all the classes IOFactory is extended to.