0

I encountered a strange StackOverflowError when using GZipOutputStream to zip TreeSet objects into byte[] arrays.

The code that does the zipping is pretty standard:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
GZIPOutputStream zip = new GZIPOutputStream(baos);
ObjectOutputStream oos = new ObjectOutputStream(new BuifferedOutputStream(zip));
oos.writeObject(this);
oos.close();
zip.close();
baos.close();

The TreeSet object contains a collection of data objects, fields in these objects are flat, i.e. no maps/lists/sets (they may have some collection fields, but they are null'ed being the TreeSet is zipped), just numbers, boolean and strings.

I read in some posts that GZIPOutputStream have this issue when dealing with complicated map structures, but there wasn't much more detail.

Does anyone know what kind of maps tend to break GZIP with such stack overflow errors? The TreeSets I'm zipping are particularly big either... The error comes up sporadically, I have not been able to self-produce it, it only happens while running in production when these TreeSets are actively used (read, adding to, and zipping).

WillZ
  • 3,775
  • 5
  • 30
  • 38
  • 1
    Gzip does not 'deal with complicated map structures' at all, only with a byte stream. It is Serialization that deals with complex structures. It has nothing to do with the zipping, it is thrown by the `ObjectOutputStream` when your object graph is too deep. – user207421 Aug 16 '14 at 02:16
  • Thanks for the top, let me look in there and see if I can find anything. My objects aren't that complex... – WillZ Aug 16 '14 at 09:42

0 Answers0