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

Fixed SimpleExpression#getArray() throwing an error when length of values array is 0 #6822

Open
wants to merge 2 commits into
base: dev/patch
Choose a base branch
from

Conversation

TFSMads
Copy link
Contributor

@TFSMads TFSMads commented Jun 27, 2024

Description

I fixed an issue where casting empty array throws an error


Target Minecraft Versions: any
Requirements: none
Related Issues: #6817

@sovdeeth sovdeeth changed the base branch from master to dev/patch June 28, 2024 15:25
@sovdeeth sovdeeth added the bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. label Jun 28, 2024
@sovdeeth sovdeeth added the 2.9 Targeting a 2.9.X version release label Jun 28, 2024
@UnderscoreTud
Copy link
Member

I think it may be better to check the class of the array. There's no reason to create a new array instance reflectively if the given array is of the correct type

@sovdeeth sovdeeth removed the 2.9 Targeting a 2.9.X version release label Jul 1, 2024
@APickledWalrus APickledWalrus added the up for debate When the decision is yet to be debated on the issue in question label Jul 1, 2024
@APickledWalrus
Copy link
Member

APickledWalrus commented Aug 17, 2024

I also question whether this is something we should be doing at all. Really, this is due to ExprXOf violating its contract. When amount is null, it returns an empty Object array (

). However, its return type is not guaranteed to be Object (which is what is occurring here). I think we are better off ensuring that all syntax are returning arrays based on their return type rather than cleaning it up for them when there is an issue.

@Moderocky
Copy link
Member

I think we are better off ensuring that all syntax are returning arrays based on their return type rather than cleaning it up for them when there is an issue.

I completely agree in principle and I spent a while trying to fix all of these bad returns in a previous PR, but what I worry is that there is no easy way to hold addons, etc. to this contract, so it's likely bad API use will slip through the net, and we either need to catch that at the first opportunity and give a proper error for it (so people know to fix it) or we need to try and accommodate it in a reasonable way, so that it doesn't error where possible.

@Pikachu920
Copy link
Member

I think we are better off ensuring that all syntax are returning arrays based on their return type rather than cleaning it up for them when there is an issue.

I completely agree in principle and I spent a while trying to fix all of these bad returns in a previous PR, but what I worry is that there is no easy way to hold addons, etc. to this contract, so it's likely bad API use will slip through the net, and we either need to catch that at the first opportunity and give a proper error for it (so people know to fix it) or we need to try and accommodate it in a reasonable way, so that it doesn't error where possible.

I would be in favor of an error

@Moderocky
Copy link
Member

I would be in favor of an error

That's fine, do you think that should be done in this PR or its own? Also, where do you think is the best place to test for the array being of the wrong (unreported) type?

@Moderocky Moderocky added the patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version. label Aug 20, 2024
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the discussion above, I would be in favor of (at most) catching this and erroring about an API violation. I'm not sure it's necessary for us to cover every misuse of the API (including this one), in fact I would prefer leaving the method as-is, but I understand the concern.

@APickledWalrus APickledWalrus removed the patch-ready A PR/issue that has been approved and is ready to be merged/closed for the next patch version. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. up for debate When the decision is yet to be debated on the issue in question
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants