getInpustream on a URL representing the whole jar file leads to java.io.IOException: no entry name specified
Alan Bateman
Alan.Bateman at oracle.com
Tue Sep 8 13:52:09 UTC 2020
On 08/09/2020 14:16, Daniel Fuchs wrote:
> Hi Jaikiran,
>
> I expect it's an incorrect use of the API. AFAICS JarURLConnection
> has always behaved like this.
>
> Opening an inputstream requires an entry, (see
> https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/jar/JarFile.html#getInputStream(java.util.zip.ZipEntry)
> and as specified, the entry in that JarURLConnection is null.
>
> You can still obtain the JarFile or read the manifest though from
> the JarURLConnection though.
>
> That said, maybe the API should be clarified to make it
> explicit that an exception will be thrown if getInputStream()
> is called on a connection that refers to a jar file (and whose
> entry/entry name is null).
I agree the javadoc could be a bit clearer as
jar:file:/tmp/some-jar.jar!/ is ambiguous. In some contexts it is a URL
to the "whole JAR file" as JarURLconnection says. In the other contexts,
including the zip file system provider, it is the URL to the top-most
directory in the JAR file, i.e. zipfs.getPath("/").toUri().
-Alan
More information about the net-dev
mailing list