Bug with the zip fs provider (7u72, 8u25), am able to create a corrupted zip...
Alan Bateman
Alan.Bateman at oracle.com
Thu Jan 15 07:31:03 UTC 2015
On 15/01/2015 00:42, Francis Galiegue wrote:
> Unfortunately I cannot write a real SSCCE. I discovered it using
> jackson-databind 2.5.0...
>
> This simple code generates an invalid zip file; no exceptions thrown:
>
> public static void main(final String... args)
> throws IOException
> {
> final Map<String, String> map
> = Collections.singletonMap("create", "true");
> final Path zipfile = Paths.get("/tmp/foo.zip");
> Files.deleteIfExists(zipfile);
> final URI uri = URI.create("jar:" + zipfile.toUri());
> final ObjectMapper mapper = new ObjectMapper();
>
> try (
> final FileSystem zipfs = FileSystems.newFileSystem(uri, map);
> final OutputStream out
> = Files.newOutputStream(zipfs.getPath("/t.json"));
> ) {
> mapper.writeValue(out, "hello");
> }
> }
>
> When I try and unzip, I get:
>
> $ unzip /tmp/foo.zip
> Archive: /tmp/foo.zip
> replace t.json? [y]es, [n]o, [A]ll, [N]one, [r]ename: A
> inflating: t.json
> error: invalid compressed data to inflate
>
>
I'm tied up with other things this week to try this but I assume the
issue is that you aren't closing the zipfs. If you change it to try
(FileSystem zipfs = ...) { ... } then I assume it should flush the
output and create the zip file.
-Alan
More information about the nio-dev
mailing list