FilePart.transferTo should accept java.nio.file.Path [SPR-16925] #21464
Labels
in: web
Issues in web modules (web, webmvc, webflux, websocket)
type: enhancement
A general enhancement
Milestone
Tomasz Elendt opened SPR-16925 and commented
In Spring 5.0
http.codec.multipart.FilePart
interface got introduced withtransferTo(File dest)
method. I think it's very unfortunate that there's a public interface being added to Spring 5.x (that specify JDK 8+ in its minimum requirements) that usesjava.io.File
instead ofjava.nio.file.Path
. Interestingly, theFile
object is completely not needed and the only implementation of that interface callsdesc.toPath
(and does not use any File-specific method).For those not familiar with differences --
java.nio.file.Path
is an interface representing a file, that has been added in Java 7. It has many advantages over oldjava.io.File
, one of which that it might be associated with custom (non-default) filesystem.A more concrete example -- if
transferTo
acceptedjava.nio.file.Path
(and there were nopath.toFile
calls) one could use in-memory filesystem, like Jimfs in their controller tests.I filed this bug report having specifically
http.codec.multipart.FilePart
API in mind, but I think that Spring should migrate tojava.nio.file.Path
in other places as well. Especially now, that support of older Java versions is dropped. I also think that no new code should be added that usesjava.io.File
- not sure if that can be verified by some static analysis tool.Affects: 5.0 GA
Issue Links:
Referenced from: commits 1e5f8cc
The text was updated successfully, but these errors were encountered: