RFR: 8235459: HttpRequest.BodyPublishers#ofFile(Path) assumes the default file system
Daniel Fuchs
daniel.fuchs at oracle.com
Thu Mar 12 10:52:37 UTC 2020
Hi Julia,
I think we need to revisit the
public static FilePublisher create(Path path)
a bit.
We should try to call Path::toFile first - whether there is a security
manager or not. In the case where that succeeds, we can use
new FileInputStream(), otherwise, we use Files.newInputStream.
It's unfortunate that new FileInputStream() and Files.newInputStream()
use different sets of exceptions, and that our public signature use
the exception thrown by the former.
Keeping using new FileInputStream() for the case where the Path::toFile
returns a file will ensure that we preserve backward compatibility
with existing code, but the current implementation of create() is
missing the case where there is no security manager and
Path::toFile doesn't throw.
If you fix that then no changes should be needed in RelayingPublishers.
best regards,
-- daniel
On 12/03/2020 10:23, Julia Boes wrote:
> Thanks for the review, Chris.
>
> After running further httpclient tests, I had to adjusted the exception
> handling of an existing test, RelayingPublishers.
>
> I also added a check in FilePublisher::createInputStream to throw if the
> path is of a directory.
>
> Updated webrev:
> http://cr.openjdk.java.net/~jboes/webrevs/8235459/webrev.02/
>
> Thanks,
>
> Julia
>
More information about the net-dev
mailing list