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

JME serialization does not work with protected/private constructors #1119

Open
Ali-RS opened this issue Jun 11, 2019 · 5 comments

Comments

Projects
None yet
4 participants
@Ali-RS
Copy link
Member

commented Jun 11, 2019

We should fix JME serialization to work with protected/private constructors. Of course, that probably requires special dispensation in Java 11.

We just have to use reflection to grab the no-arg constructor and make setAccessible(true) or whatever.

Links to the forum page in case:
https://hub.jmonkeyengine.org/t/jme-serialization-does-not-work-with-protected-private-constructor/41946
https://hub.jmonkeyengine.org/t/solved-need-help-with-triplanar-texturing-on-a-box/41940/24?u=ali_rs

@Sailsman63

This comment has been minimized.

Copy link

commented Jun 17, 2019

What, in general, would a fix here look like?

The serialisation schemes that I've run across generally do require a public, no-arg constructor. Otherwise, you're playing monkey-games with Reflection.

Or are you just running into cases where the class was inappropriately built with private constructors?

@pspeed42

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2019

The fix would look like playing games with reflection. Games are already being played with reflection to access private fields, etc. in the SpiderMonkey serialization.

We require no-arg constructors but often it makes the classes themselves very fragile to have public no-arg constructors. Any time you see "Provided for serialization, do not call" as a javadoc comment on a public constructor we should feel sad.... there's no reason for it.

@pspeed42

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2019

This PR came from another discussion and it's too bad none of the conversation was copied over or a link... because I also don't have the link handy anymore.

@Ali-RS

This comment has been minimized.

Copy link
Member Author

commented Jun 17, 2019

Description and links to the forum page added in the first post.

@stephengold

This comment has been minimized.

Copy link
Contributor

commented Jun 17, 2019

Many times I've been bitten by no-arg constructors that I invoked when I wasn't supposed to. Playing monkey games with reflection would be a small price to pay to avoid such errors.

Also: imho, monkey games are very much in the spirit of jMonkeyEngine.

@stephengold stephengold added this to the v3.3.0 milestone Jul 8, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.