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

There's a possibility of java.lang.NullPointerException when trying to open a GUI #28

Open
wtlgo opened this issue Mar 30, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@wtlgo
Copy link

wtlgo commented Mar 30, 2024

The plugin can cause a java.lang.NullPointerException when a player is trying to open a GUI.

In PlayerManager.findPlayer method there is a possibility that the method returns null if createError != null

	public SkullUser findPlayer(@NonNull final UUID uuid) {
		final AtomicReference<SkullUser> skullUser = new AtomicReference<>(this.players.getOrDefault(uuid, null));

		if (skullUser.get() != null) return skullUser.get();

		Skulls.getDataManager().insertPlayer(new SkullPlayer(uuid, new ArrayList<>()), (createError, created) -> {
                        // Oh no, an error has happened....
			if (createError == null) { // That's why we are skipping this part...
				addPlayer(created);
				skullUser.set(created);
			}

                        // error is not handled in any meaningful way, the user is not aware that something wrong has happened...
		});

               // That's why we return null...
		return skullUser.get();
	}

This messes up with SkullsViewGUI constructor, because the result of PlayerManager.findPlayer is passed there as is at many places, and it will throw a java.lang.NullPointerException exception

	public SkullsViewGUI(final Gui parent, final SkullUser skullPlayer /* == null */, final String category, final ViewMode viewMode) {
                /* ... */
		this.skullPlayer = skullPlayer;
		this.player = Bukkit.getPlayer(this.skullPlayer.getUUID()); // <- Oops!
                // A NullPointerException happened and is not caught, now it is all over the logs, the user is confused...
		draw();
	}

I can't really suggest a good way to fix this, since I'm not fully familiar with the code base yet, but I think you would like to be aware of this problem.

@wtlgo wtlgo added the bug Something isn't working label Mar 30, 2024
@kiranhart kiranhart self-assigned this Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants