Skip to content

FilePart.transferTo should accept java.nio.file.Path [SPR-16925] #21464

Closed
@spring-projects-issues

Description

@spring-projects-issues

Tomasz Elendt opened SPR-16925 and commented

In Spring 5.0 http.codec.multipart.FilePart interface got introduced with
transferTo(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 uses java.io.File instead of java.nio.file.Path. Interestingly, the File object is completely not needed and the only implementation of that interface calls desc.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 old java.io.File, one of which that it might be associated with custom (non-default) filesystem.

A more concrete example -- if transferTo accepted java.nio.file.Path (and there were no path.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 to java.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 uses java.io.File - not sure if that can be verified by some static analysis tool.


Affects: 5.0 GA

Issue Links:

Referenced from: commits 1e5f8cc

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions