-
Notifications
You must be signed in to change notification settings - Fork 124
Fix NPE when banning/unbanning person that isn't known #652
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
base: master
Are you sure you want to change the base?
Conversation
This doesn't solve the original issue, refer to my previous comment:
As this may cause issues on other sections using said getId if it somehow manages to pass a previous check to ensure the name is valid. if this is reproducible under spigot, then I'm glad to look further into it. If this isn't, then this is likely an issue towards paper. |
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.
Please describe the following provided in the above comment:
How does this resolve the original issue? The original issue refers to something outside of AdvancedBan not correctly handling parsing a username. Can this be reproduced under spigot?
Hi @Hopefuls : this does not fix the original issue of course. Because that needs to be done in paper then. However, I left it here (and didn't respond) because I consider it a bad habbit to just let exceptions bubble up. Especially if it's as clear as this one here. As in this case: the library should protect against the bubbling exception and present a clean alternative message to the end-user. And actually paper is correct. It's an exception as the username is incorrect. So they should throw it. But the plugins should catch the exception. I will have a look tonight what happens when I run it on a spigot server, but I'm assuming it will be similar. But I keep an open mind, so let's see later. |
I ran this against spigot, and same thing happened:
|
Was able to reproduce with the same username, this can be reproduced the following way:
The error originates from:
it is not that this is an easy fix to just try catch, it is more worrying that this is not properly handled in the server software itself. This is a bug from bukkit (Unless modified by purpur in this case).
|
private void ban(BanList banlist, PunishmentEvent e) { | ||
try { | ||
banlist.addBan(e.getPunishment().getName(), e.getPunishment().getReason(), new Date(e.getPunishment().getEnd()), e.getPunishment().getOperator()); | ||
} catch (NullPointerException ex) { | ||
Bukkit.getLogger().severe("No player is known by the name '" + e.getPunishment().getName() + "'"); | ||
} | ||
} |
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.
Can this be further specified to only catch when the error originates from:
Cannot invoke "com.mojang.authlib.GameProfile.getId()" because "var0" is null
As this may catch-all issues that are not related to this issue.
(Also apply to the pardon too)
Thanks for your help!
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 can give you access to the PR if you want as I'm not able to fix this within the next week.
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 think I now fixed it better. The problem is that I don't want to check for a certain text in the error message. Neither would I like to go parsing the stack trace. Nor do something with reflection.
The negative thing with the current implementation is that a user has to have been logged on before he's allowed to be banned...
Neither option truly satisfies me, even more because there is no real internal method that I can query (without the use of reflection / fork-specific calls) to check the existence of the username.
So when the player isn't known, you can ban them, but when pardoning them, it will give a NPE.
This fix resolves that nasty error and shows a nicer error message.
Closes #650
Before:
After: