groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Johnson <>
Subject serializing closures
Date Thu, 31 Oct 2019 20:30:05 GMT
I've got a system with two apps, both of which read and write a large file
of serialized objects.   One object, actually, which is "the database".
 I've been updating this system to run under 2.5.8 and finally got around
to testing the first app writing this file and the second app reading it.
  All the objects that are in "the database" are defined in a library that
both apps use, so there haven't been many problems in the past, except for
the usual one of adding a new class and forgetting to make sure it is

I am getting an invalidClassException because the serialVersionUIDs don't
match, but the class that is not matching is a class for a closure.   In
other words, I didn't create this class, this is a class that Groovy
creates to implement a closure.   This raises many questions.

My system goes to some trouble to NOT serialize closures.   So, my real
problem is figuring out where I am referring to a closure where I shouldn't
be.   That is not the point of this message.   Instead, it is:
 1) Wow!  You can serialize closures?   I wonder how that can work?   I
suppose you should only evaluate them and get a return value.   You
shouldn't raise an exception or anything funky like that.  Serializing them
must serialize everything that the closure references.
2) So the Groovy compiler won't give the same serialVersionUID to the same
closure class compiled two different times?   Doesn't that sort of defeat
the purpose of serializing closures?   Or is something causing this
problem, like using two different versions of the Groovy compiler?  As far
as I can tell, I am using the same version for both programs.

I always assumed that you couldn't serialize closures.   It would be
helpful to me if there were a way to cause an error when I tried to write
out a closure, rather than waiting until I read it back in.

-Ralph Johnson

View raw message