-
-
Notifications
You must be signed in to change notification settings - Fork 751
Fix MemberCacheViewImpl#getElementsWithRoles and Guild#findMembersWithRoles ignoring the public role #2297
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 MemberCacheViewImpl#getElementsWithRoles and Guild#findMembersWithRoles ignoring the public role #2297
Conversation
src/main/java/net/dv8tion/jda/internal/utils/cache/MemberCacheViewImpl.java
Outdated
Show resolved
Hide resolved
8a80a48
to
b29df7f
Compare
b29df7f
to
0039ef9
Compare
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.
Another thing:
The JavaDocs of Guild#getMembersWithRoles
states it will be checked if roles are from a different guild. But according to the impl, this is not the case. Could you add that check?
Only Guild#findMembersWithRoles
checks for that yet.
src/main/java/net/dv8tion/jda/internal/utils/cache/MemberCacheViewImpl.java
Show resolved
Hide resolved
One another thing: I'm not sure if it is a good idea to call Can somebody confirm it's okay? |
That method seems to be broken too. |
I think you are right. I thought doing it for
Sadly, this is not really a good performance improvement since this will still iterate each member ( Perhaps in a different MR, this could be adjusted but it's definitely not in the scope of this MR. |
Re commit 2480ef9: Couldn't you add that role check to |
I don't think that's possible because |
True, didn't saw that, thanks. Speaking about |
@Nonnull | ||
default List<Member> getMembersWithRoles(@Nonnull Role... roles) | ||
{ | ||
Checks.noneNull(roles, "Roles"); | ||
Checks.notNull(roles, "Roles"); | ||
return getMembersWithRoles(Arrays.asList(roles)); | ||
} |
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.
No, you got me wrong. As said before, it can't be null due to two methods having the the same name and the same number of parameters. The compiler would simply not allow it without explicit casting. And if somebody does that, it's more or less their fault imo.
And no need to check for noneNull
again since you already do that in getMembersWithRoles(List<Role>)
. So you can remove that check again (or delete the last two commits via. rebase).
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.
That method has to check notNull
otherwise something like Role[] roles = null; guild.getMembersWithRoles(roles);
would cause Arrays#asList
to throw an NPE
And no need to check for
noneNull
again since you already do that ingetMembersWithRoles(List<Role>)
Yes
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.
That method has to check notNull otherwise something like Role[] roles = null; guild.getMembersWithRoles(roles); would cause Arrays#asList to throw an NPE
Yes, technically you're right. But as said, you would explicitly need to cast it / define it like that so it compiles. And as a user you should see this is simply wrong. So imo it's fine to let the user run into this. Because essentially you just trade a NullPointerException
with an IllegalArgumentException
. Doesn't help much but needs more code (maintenance).
From what I see it's also not used in other places and consistency is more important. So imo, it's really fine to remove that check again.
Just checked it again, it's actually used in MemberCacheViewImpl#getElementsWithRoles
.
So my bad, it should actually stay since as I just said, consistency is more important. Good catch!
Added the semi-breaking tag as this is a long standing behavioral change that might effect existing code. |
Pull Request Etiquette
Changes
Closes Issue: #2291
Description
Fixes an issue that caused
MemberCacheViewImpl#getElementsWithRoles
to return an empty list when given the public role.