StaticFile.fromFile IllegalArgumentException with large files
See original GitHub issueThe following code results in an IllegalArgumentException when the file is longer than Int.MaxValue
case req@GET -> Root / "file" =>
StaticFile.fromFile(new File("massive-file.txt"), Some(req)).getOrElseF(NotFound())
And the exceptionis
logtype="application" transaction_id="" req_time="2017-11-15T10:53:34.195+11:00" loglevel="ERROR" threadname="scala-execution-context-global-73" classname="o.h.b.p.Stage" linenumber="Http1ServerStage.scala:226" message="Error writing body"
java.lang.IllegalArgumentException: null
at java.nio.ByteBuffer.allocate(ByteBuffer.java:334)
at fs2.io.file.FileHandle$$anon$2.read(FileHandle.scala:160)
at org.http4s.StaticFile$._readAllFromFileHandle0$1(StaticFile.scala:150)
at org.http4s.StaticFile$.readAllFromFileHandle$1(StaticFile.scala:145)
at org.http4s.StaticFile$.$anonfun$fileToBody$7(StaticFile.scala:160)
at org.http4s.StaticFile$.$anonfun$fileToBody$7$adapted(StaticFile.scala:160)
Some background as to how / why I discovered this. I was looking into streaming of large responses and noticed that the JVM CPU usage is very high while doing so. I wasn’t expecting this as I expect that Streaming of a large response is largely IO. To narrow down to the least possible application code I decided just to stream a large file. CPU usage is still higher than what I’d expect. I’m still investigating.
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Convert file: Uri to File in Android - Stack Overflow
I am getting java.lang.IllegalArgumentException: Expected file scheme in URI: content://com.shajeel.daily_monitoring.localstorage.documents.
Read more >File (Java Platform SE 8 ) - Oracle Help Center
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified...
Read more >Files (Guava: Google Core Libraries for Java 21.0 API)
Parameters: file - the file to read from; Returns: a byte array containing all the bytes from file; Throws: IllegalArgumentException - if the...
Read more >guava/src/com/google/common/io/Files.java - Google Git
@return a byte array containing all the bytes from file. * @throws IllegalArgumentException if the file is bigger than the largest.
Read more >FileUtil (File System API)
Finds an unused file name similar to that requested in the same folder. ... Throws: IllegalArgumentException - if listener was not listening to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That exception happens when you allocate a negative buffer size. I bet the
.toInt
is the villain of this story.I fixed this while looking at #1555. PR coming.