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

Preventing NullPointerException when calling Via.getManager().addEnableListener() after manager is initialized #3779

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

wtlgo
Copy link

@wtlgo wtlgo commented Apr 6, 2024

If an external plugin calls Via.getManager().addEnableListener() after Via.getManager().init() has been called, it causes a NullPointerException. In this pull request, to prevent this issue, if the manager is already initialized, it immediately executes the listener instead of raising an exception and causing the external plugin to fail during its loading process.

@wtlgo wtlgo changed the title Avoid NullPointerException in case Via.getManager().addEnableListener() is called after the manager is initialized Preventing NullPointerException when calling Via.getManager().addEnableListener() after manager is initialized Apr 6, 2024
@kennytv
Copy link
Member

kennytv commented Apr 7, 2024

What's the use case here? If any of our plugins call this too late, this should mean failure (though ofc the exception could be better), also just being internal api

@wtlgo
Copy link
Author

wtlgo commented Apr 7, 2024

What's the use case here?

E.g. If the external plugin is loaded by another plugin during the loading phase via let's say Bukkit.getPluginManager().loadPlugin() it is quite literally impossible to manage the external plugin to call addEnableListener before ViaVersion calls init even though it is not misconfiguration, as all it tries to do is not to run its ViaVersion-dependent init process before ViaVersion is ready, and as result both ViaVersion and plugin in question would function just fine.

Also, this is not "just internal API", as it is exposed by com.viaversion:viaversion-api.

@kennytv
Copy link
Member

kennytv commented Apr 7, 2024

Is that external plugin one of ours, or one you can change the method call in? The current name doesn't really imply any immediate execution and even in your scenario should still provide a warning. Assuming this is about ViaBackwards or Rewind, this will lead to peformance issues, possibly even more so in the future, due to missing data availability on load

@FlorianMichael
Copy link
Member

Maybe we could consider moving this into common since it's not really API other plugins should use?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants