groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Schalk W. Cronjé <>
Subject Re: serializing closures
Date Thu, 31 Oct 2019 22:46:51 GMT

In short in the asciidoctor-gradle-plugin we serialise closures out because by default we
run asciidoctorj in a separate JVM.Basically you have to dehydrate the closure before serialisation
and then rehydrate it after deserialisation. This is to set an owner & delegate.Sent from
my Samsung device

-------- Original message --------
From: Ralph Johnson <> 
Date: 31/10/2019  21:30  (GMT+01:00) 
Subject: serializing closures 

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 serializable.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
View raw message