serializing closures

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

serializing closures

Ralph Johnson-2
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 Johnson
Reply | Threaded
Open this post in threaded view
|

Re: serializing closures

ysb33r
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 <[hidden email]>
Date: 31/10/2019 21:30 (GMT+01:00)
To: [hidden email]
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 Johnson