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).