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

default to an empty string in Emoji#fromData #2172

Closed
wants to merge 1 commit into from
Closed

default to an empty string in Emoji#fromData #2172

wants to merge 1 commit into from

Conversation

sebm253
Copy link
Contributor

@sebm253 sebm253 commented Jul 5, 2022

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: NaN

Description

this PR fixes possible exceptions when name in emoji objects is null, as mentioned in this example in the api docs.

EmojiUnion rEmoji = Emoji.fromData(emoji);

Copy link
Contributor

@DManstrator DManstrator Jul 5, 2022

Choose a reason for hiding this comment

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

nit: For consistency reason I would add that newline back or remove it too from the MessageReactionClearEmojiHandler and have the same variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think anything mentioned matters at all. in MessageReactionClearEmojiHandler, I think the variables passed into new MessageReaction(...) were just meant to be separated, same with MessageReactionHandler and the check.

@Mitmocc
Copy link
Contributor

Mitmocc commented Jul 5, 2022

There is no real purpose to this. It skips over the check for null and ends up throwing an IllegalArgumentException because of an empty name. I guess the exception is a little bit better to understand but also misleading as the name is not empty but null

@@ -174,7 +174,7 @@ static EmojiUnion fromData(@Nonnull DataObject emoji)
if (emoji.isNull("id"))
return (EmojiUnion) fromUnicode(emoji.getString("name"));
else
return (EmojiUnion) fromCustom(emoji.getString("name"), emoji.getUnsignedLong("id"), emoji.getBoolean("animated"));
return (EmojiUnion) fromCustom(emoji.getString("name", ""), emoji.getUnsignedLong("id"), emoji.getBoolean("animated"));
Copy link
Contributor

@Mitmocc Mitmocc Jul 7, 2022

Choose a reason for hiding this comment

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

I want to suggest changing this from "" to "null". Discord can at times send a message object containing a reaction with a null name (occurs every now and then when the bot is adding multiple reactions to a message and more often when users are clicking the reactions while the bot is still applying new ones).

So normally an exception is thrown but the exception is pretty useless as there is nothing the JDA user can do to prevent it and there is no reason to not still build the message object with the proper reactions, even if one of the reactions will have the name "null". Your suggested fix would still throw an exception as the empty name would be checked in the fromCustom method.
Setting the name to "null" however removes the unnecessary exception and builds the message object more accurately (doesn't skip over the reaction with the null name, just builds the reaction with the name "null".

@MinnDevelopment
Copy link
Member

Thank you, but I would like to keep the checks the way they are right now in the Emoji factory methods. Instead, I'm adding EntityBuilder.createEmoji as an unchecked alternative to Emoji.fromData in #2176

@sebm253 sebm253 deleted the patch/emote-name-default branch July 10, 2022 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants