#1008 Check that OfflinePlayer's name is not null

- Add check
- Create test
This commit is contained in:
ljacqu 2016-11-19 17:36:05 +01:00
parent 30343d7587
commit dda7bd5cb5
2 changed files with 22 additions and 1 deletions

View File

@ -72,7 +72,7 @@ class PurgeTask extends BukkitRunnable {
}
OfflinePlayer offlinePlayer = offlinePlayers[nextPosition];
if (toPurge.remove(offlinePlayer.getName().toLowerCase())) {
if (offlinePlayer.getName() != null && toPurge.remove(offlinePlayer.getName().toLowerCase())) {
if (!permissionsManager.hasPermissionOffline(offlinePlayer, PlayerStatePermission.BYPASS_PURGE)) {
playerPortion.add(offlinePlayer);
namePortion.add(offlinePlayer.getName());

View File

@ -124,6 +124,27 @@ public class PurgeTaskTest {
assertRanPurgeWithNames("foxtrot");
}
/**
* #1008: OfflinePlayer#getName may return null.
*/
@Test
public void shouldHandleOfflinePlayerWithNullName() {
// given
Set<String> names = newHashSet("name1", "name2");
OfflinePlayer[] players = asArray(
mockOfflinePlayer(null, false), mockOfflinePlayer("charlie", false), mockOfflinePlayer("name1", false));
reset(purgeService, permissionsManager);
setPermissionsBehavior();
PurgeTask task = new PurgeTask(purgeService, permissionsManager, null, names, players);
// when
task.run();
// then
assertRanPurgeWithPlayers(players[2]);
}
@Test
public void shouldStopTaskAndInformSenderUponCompletion() {
// given