[CLJ-913] slurp fails on /proc files (linux) Created: 19/Jan/12 Updated: 01/Mar/13 Resolved: 29/Feb/12
|Affects Version/s:||Release 1.3|
On my machine,
whereas the following succeeds:
|Comment by Tassilo Horn [ 23/Jan/12 8:57 AM ]|
It seems this is not an error in Clojure but an error in the native implementation of FileInputStream.available(). For example, this Java code throws the same exception.
Tested with sun-jdk 126.96.36.199 and IcedTea 7.2.0.
|Comment by Andy Fingerhut [ 20/Feb/12 7:42 PM ]|
This is not a fix, but a workaround for this issue with the JVM: call slurp on a reader that you force to be constructed as unbuffered. For example:
(slurp (java.io.InputStreamReader. (java.io.FileInputStream. "/proc/cpuinfo")))
(tested with Sun/Oracle JDK 1.7.0_02)
This is less efficient for large files, so I wouldn't recommend that the slurp code be modified to work this way for all files.
One can imagine an implementation of Clojure slurp and clojure.java.io/reader that first tried the slurp call with buffered I/O, and if an exception like this one occurs fall back to unbuffered I/O. However, that sounds like it would get very hairy very quickly, and would be difficult to write it in such a way that it did not mask I/O errors that should be visible to the caller. Also that seems like unwanted complexity in Clojure to work around what is likely a bug in the JVM. Someone (Tassilo?) filed a bug with Oracle about this exception:
|Comment by Andy Fingerhut [ 29/Feb/12 1:06 AM ]|
I contacted Romain, the submitter, and they agreed that trying to work around this JVM bug in Clojure's slurp might be a bit excessive, and that closing the ticket was reasonable.
I have added a note about Romain's workaround at http://clojuredocs.org/clojure_core/1.3.0/clojure.core/slurp in hopes that others will be able to find it more easily.