-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: prevent serialisation of private component fields #5208
feat: prevent serialisation of private component fields #5208
Conversation
295928c
to
a0c9384
Compare
cross-post from Discord for the record:
what I did in JS: I gave myself a chest and some furnaces and sifting tables, placed them, put some stuff in them and then tried to exit to main menu (and it was a fresh TS workspace with JS recursed) @BenjaminAmos responded:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to figure out how to deal with the RetainComponentsComponent
issue before we can merge this.
Although I'm wondering why it shows up ... didn't I change all private component fields to public? 🤔
…into feat/no-private-component-field-serialisation
…eldMapTypeHandler by default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests out fine and looks good to me.
Only question: can we have some additional tests for the new behavior?
} catch (InvocationTargetException e) { | ||
logger.error("Failed to involve getter for field {}", field); | ||
continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need something similar below for the setter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that the setter is caught in the general catch block here:
Lines 110 to 112 in ae83461
} catch (Exception e) { | |
logger.error("Unable to deserialize {}", data, e); | |
} |
I will add a more specific catch for that error to make it less ambiguous though.
logger.atWarn().addArgument(field.getName()).addArgument(rawType.getTypeName()). | ||
log("Field {}#{} will not be serialised. Terasology no longer supports serialising private fields."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why fluent API usage here?
I would expect getName()
and getTypeName()
to be O(1) so pretty much neglectable... also this is not on the happy path so it's not expected to be evaluated often...
In my test run, I got the warning only twice:
19:18:19.310 [main] WARN o.t.p.t.c.f.ObjectFieldMapTypeHandlerFactory - Field exists#org.terasology.engine.entitySystem.entity.internal.PojoEntityRef will not be serialised. Terasology no longer supports serialising private fields.
19:18:19.396 [parallel-1] WARN o.t.p.t.c.f.ObjectFieldMapTypeHandlerFactory - Field entityRef#org.terasology.engine.persistence.internal.DelayedEntityRef will not be serialised. Terasology no longer supports serialising private fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, guess it might've been a PMD warning in that case.
I'd prefer suppressing the warning (suffix with //NOPMD
) here due to the above-mentioned reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i am a little confused - git blame says @BenjaminAmos changed that line. commit 873fe5b changed ComponentTypeHandlerFactory, different file, but the change looks the same? in case i really did this, feel free to undo. 2 warnings, one line too long, and one for the logger are there in the line before.
a lot better than before. with joshuasworld i get, and i seem recall that i had this before and it was my setup, some module missing isn't it?
|
@soloturn yes you faced that before: Terasology/JoshariasSurvival#76 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not hold off merging. this improves a lot and finally saves stuff again.
Contains
This pull request adds a newComponentTypeHandlerFactory
type specifcally for serialising components. It is mostly the same asObjectFieldMapTypeHandlerFactory
(fromTypeHandlerFactory
) but with an additional check for private fields. It might be possible to merge the two classes instead, this is just a first attempt to see how it behaves.It is not possible to exclude private field serialiation fromObjectFieldMapTypeHandlerFactory
completely since NUI depends on this behaviour extensively for UI widgets.This pull request removes the ability to serialise private fields in
TypeHandlerLibrary
, apart from in a few special cases (mainly NUI). It changes the genericObjectFieldMapHandler
to use getter and setter methods where available instead.How to test