This error is present in the latest JDK versions 1.7 and 1.8 (7u72, 8u25). Requires: jackson-databind 2.5.0. Tested on Linux x86_64 (more precisely, Ubuntu 14.10).
the code:
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"); } }
As a result, an invalid zip file is created:
$ 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 initially discovered an error in the Jackson error tracker , even if it really is not the culprit, and a solution was found to circumvent it: disable JsonGenerator.Feature.AUTO_CLOSE_SOURCE in ObjectMapper . This option, which is enabled by default, tells the linker to close the stream.
While I would like to open an error for Oracle, I would first like to write SSCCE, but I can not. I tried closing the stream twice (since it was closed twice in the example), not using the try-with-resources statement, etc. To no avail.
Can you come up with SSCCE for this problem?
fge
source share