-
-
Notifications
You must be signed in to change notification settings - Fork 734
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
Conversation
EmojiUnion rEmoji = Emoji.fromData(emoji); | ||
|
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.
nit: For consistency reason I would add that newline back or remove it too from the MessageReactionClearEmojiHandler
and have the same variable name.
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 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.
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")); |
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 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".
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 |
Pull Request Etiquette
Changes
Closes Issue: NaN
Description
this PR fixes possible exceptions when
name
in emoji objects isnull
, as mentioned in this example in the api docs.