-
-
Notifications
You must be signed in to change notification settings - Fork 308
Make property changes more robust #2962
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
Conversation
|
We should keep the exception, else we're just silently failing. No failure implies it should have "worked" |
| public boolean hasPropertyOfType(PropertyKey key, Class<?> propertyType) { | ||
| int ordinal = key.getId(); | ||
| Property<?> property; | ||
| return this.settings.propertiesMapArr.length > ordinal |
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.
Does this definitely make sense to have? If the key ID is dynamic to the original block state, that may not work, and if it's global that wouldn't work either?
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.
Our PropertyKey and its ID are unique, so they are at the same position in each propertiesMapArr. But the actual property class stored there can have different types in different arrays.
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 cool, so just a quick and dirty check so we don't need to check further
Probably worth to note that the default impl of |
I think I'm looking at the wrong getIndex method - it seems like it returns -1 on failure? in all overrides? |
E.g. Lines 39 to 42 in 8c01959
Boolean arguments. The compiler adds a synthetic bridge method getIndex(Object) that basically just delegates but with a cast. That's where we fail then.
|
Ah yeah of course, missed that. I wonder if we should keep that though - having the "wrong" value of the right type return -1 is okay, whereas the wrong type altogether feels like a larger error (as would be the case for nearly/if not all other generic-type situations like this). As it is the default implementation would throw a CCE if the wrong type is given anyway |
|
Can the check also be added to other places (e.g. https://github.com/IntellectualSites/FastAsyncWorldEdit/blob/main/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java#L321 // https://github.com/IntellectualSites/FastAsyncWorldEdit/blob/main/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/SnowSimulator.java#L124-L129 )? Related to #2963 - what should we do in that case? |
|
So this isn't actually fully fixing the issue. It's possible to have properties of the same type, with the same length of values, and the same name (i.e. slab and chest |
PierreSchwang
left a comment
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.
LGTM
Overview
Fixes #2961
Description
Different block types can share a property with the same name but with different types. In such case, we shouldn't try to apply the property with invalid values.
We could probably also remove the
IllegalArgumentExceptionand just return the current block state instead inBlockState#with(PropertyKey,V), but that might hide other problems. Thoughts?