Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeException when serializing nested class #37

Closed
jswaelens opened this issue Nov 3, 2014 · 16 comments
Closed

RuntimeException when serializing nested class #37

jswaelens opened this issue Nov 3, 2014 · 16 comments
Labels

Comments

@jswaelens
Copy link

Hello,

I am getting an error when I serialize a private nested class, because its parent (the one where the inner class is defined in) is not serializable. I was not expecting that the parent class would also be serialized, this seems a bit odd ... and possible not intended? Moving the particular class to its own type resolved the issue, but we might have more cases like this yet to be detected.

This is on version 1.55 (JRE 6 compatible version).

Please advise on the best way to proceed.

thanks!

@RuedigerMoeller
Copy link
Owner

Hi,
any inner class contains a hidden reference (this$0) to its outer class, therefore has to get also serialized. This is not an invention of fst but standard java and cannot be changed as the inner class code accesses methods + state, it requires it to work properly.

I have done tweaks in the past to explicitely null the value of this$0 [by registering a custom serializer+using reflection], however this leads to NPE at receiver side once methods/fields of the outer class are accessed ofc.

In order to make an inner class serializable, declare it static "static class ..". In case you need a ref to outer instance, define it explicitely and make it transient. You somehow need to set it then after deserialization.

@jswaelens
Copy link
Author

Hello,

Thanks for your feedback, I'll apply the 'static' approach when it comes up again. I fixed this case using 'transient' variables since those giving the serializable error shouldn't have been serializing in the first place.

Just fyi, we only got this error on that particular are once we switched from using 'ObjectOutputStream' to 'FSTObjectOutput' which means that there must be some subtle difference somehow.

thanks

@RuedigerMoeller
Copy link
Owner

"Just fyi, we only got this error on that particular are once we switched from using 'ObjectOutputStream' to 'FSTObjectOutput' which means that there must be some subtle difference somehow."

Can you provide an reproducing example ?. I am not aware of a difference there and would like to find out.

@RuedigerMoeller
Copy link
Owner

Btw, the newest 1.x builds are also 1.6 compliant

@jswaelens
Copy link
Author

Sure, I'll try to create something which resembles the composition we have
and see what it does. I'll get back to you.

On Mon, Nov 3, 2014 at 12:21 PM, RuedigerMoeller notifications@github.com
wrote:

"Just fyi, we only got this error on that particular are once we switched
from using 'ObjectOutputStream' to 'FSTObjectOutput' which means that there
must be some subtle difference somehow."

Can you provide an reproducing example ?. I am not aware of a difference
there and would like to find out.


Reply to this email directly or view it on GitHub
#37 (comment)
.

@RuedigerMoeller
Copy link
Owner

That would be great :-)

@jswaelens
Copy link
Author

Hello,

Please find a test eclipse project here: https://github.com/jswaelens/testFST

You can toggle the use of std serialization and fst in 'be.foo.bean.TestBean.doSomething()' by manipulating the boolean. Set it to false to use the standard object serialization and true to use FST.

It seems to be triggered by having an abstract class with a non serializable sub-class - maybe it is some edge case?

thanks!

@RuedigerMoeller
Copy link
Owner

Awesome. Thanks a lot. As I'll be off to Goto 2014 it might take some days until I can check it out.

@jswaelens
Copy link
Author

No problem, glad to be able to help!

On Tue Nov 04 2014 at 8:49:25 PM RuedigerMoeller notifications@github.com
wrote:

Awesome. Thanks a lot. As I'll be off to Goto 2014 it might take some days
until I can check it out.


Reply to this email directly or view it on GitHub
#37 (comment)
.

@RuedigerMoeller
Copy link
Owner

Hm .. looks like a JDK bug to me on a first glance. I see there is an instance of a non-serializable class coming in and getting written ..

BTW you should upgrade to 1.63 (some fixes).

@jswaelens
Copy link
Author

Yep, it is weird that it doesn't throw the not Serializable error indeed.
I'll update our libs, thanks for the pointer.

On Tue, Nov 4, 2014, 21:18 RuedigerMoeller notifications@github.com wrote:

Hm .. looks like a JDK bug to me. BTW you should upgrade to 1.63 (some
fixes).


Reply to this email directly or view it on GitHub
#37 (comment)
.

@RuedigerMoeller
Copy link
Owner

Its definitely a JDK bug. I was able to serialize a directbytebuffer. However the deserialized object had wrong values. Funny :-)

https://github.com/RuedigerMoeller/fast-serialization/tree/master/src/test/jdk_bug/foo

@RuedigerMoeller
Copy link
Owner

will create a new label 'jdk-bug' =)

@jswaelens
Copy link
Author

Ah, always nice to find a bug in the ye 'old JDK! Do you want me to log it
or did you do that already - or shouldn't we bother?

On Wed Nov 05 2014 at 1:40:16 AM RuedigerMoeller notifications@github.com
wrote:

Its definitely a JDK bug. I was able to serialize a directbytebuffer.
However the deserialized object had wrong values. Funny :-)


Reply to this email directly or view it on GitHub
#37 (comment)
.

@RuedigerMoeller
Copy link
Owner

you found it, so just let me know if you want to report it. In case you don't I will do ..

@jswaelens
Copy link
Author

Okey, submitted - I'll keep you posted ;-)

On Wed Nov 05 2014 at 10:08:46 AM RuedigerMoeller notifications@github.com
wrote:

you found it, so just let me know if you want to report it. In case you
don't I will do ..


Reply to this email directly or view it on GitHub
#37 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants