Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fix: do not crash on unexpected map format in GenericMapTypeHandler #5062
fix: do not crash on unexpected map format in GenericMapTypeHandler #5062
Changes from all commits
9496503
c1aba4c
f5869a2
cbb6a8c
a92641b
67bca4f
4a8f40a
ba6b2be
fbe4e10
6e5ed50
1673268
db97071
bb8d54e
6f5a1b2
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
@keturn I saw the test cases in
GenericMapTypeHandlerTest.java
and wanted to ask why it's desirable to have an empty map returned in case of a mismatched key / value handler...? My current assumption is that we might want that because failing to deserialize theChangingBlocks
component should not result in the whole prefab deserialization failing (although I'm not even sure that would be the case when returningOptional.empty()
instead 🤔Can you confirm this assumption or otherwise explain the reason for expecting an empty map in this case?
My intention with using
Optional.empty()
here is to indicate that the serialization failed but not return a half-way deserialized map as might happen for instance in case the prefab holds:With returning
Optional.of(result)
, I would expect the first map entry to be put into the result map and the deserialization failing for the second entry, resulting in a half-way deserialized map which might lead to weird and potentially hard to debug behavior in game.Taking the growing plant feature, for example, the plant would never grow to the second stage as the second stage never ended up in game because its deserialization failed.
Please correct me if I got any of the type handling logic etc. wrong leading to incorrect assumptions/expectations 😅
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.
It looks like I wrote those test cases after @skaldarnar wrote the implementation, so we should ask that guy too.
I'm struggling with how to answer these questions because I think you raise some good points, and—
Optional.empty
here, because I feel likeOptional
is bad at communicating error states and I've felt frustrated with trying to use it here myself, andThere 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.
Maybe we can add the JSON equivalent we want to express here in a comment? Probably helps in both understanding the test case and figuring out if the data strucutre represents the thing we want to test.
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.
done ✔️
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.
😟 It's also the textbook example of "comment that's out of date as soon as you change the code."
If you think it helps despite that, go ahead and keep it, but I'm a little concerned.
Also note Javadoc does not have triple-quote code blocks. Either change these to javadoc syntax, or do not start the comment with the double-asterisk
/**
so IntelliJ and javdoc don't treat it as javadoc.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've replaced the triple-quotes.
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.
This is the case I'm a little worried about, since it's a change from the previous behavior. Not that the previous behavior was better, but it's one of those things where something might have been implicitly depending on it.
But this has a test case now, and the hypothetical I'm worrying about doesn't, so this wins.
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 don't think (or hope) something was depending on it. Rather, we'll see some things either work out better or even worse than before, hopefully just epxosing the underlying problem better.
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.
My expectation is that if this makes something work worse than before, then it's mainly making the underlying issue more visible than before.
I ran into the crash after making
ChangingBlocks
use uris instead of strings for the map key.The prefabs in PlantPack that I tested this were working before with the basic string key type map deserialization but didn't have the format required by the generic map type handler (outer array, entries with "key" and "value" keys). So the three malformatting test cases are covering this now.
Edit: Just saw that Skal already answered to this and with way more detail 😅 Thanks for that! ❤️