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

rsp Nullpointerexpcetion #160

Open
Huh-DIETHGOD opened this issue Sep 30, 2023 · 4 comments
Open

rsp Nullpointerexpcetion #160

Huh-DIETHGOD opened this issue Sep 30, 2023 · 4 comments

Comments

@Huh-DIETHGOD
Copy link

depend: [PlaceholderAPI, Vault, XConomy]
api-version: 1.16

Error occurred while enabling UltimateRPGPlugin v0.0.1 ALPHA (Is it up to date?)
java.lang.NullPointerException: null
at Ultimate.huh.core.UltimateRPGPlugin.setupChat(UltimateRPGPlugin.java:150) ~[?:?]
at Ultimate.huh.core.UltimateRPGPlugin.onEnable(UltimateRPGPlugin.java:53) ~[?:?]

IDE:
Method invocation 'getProvider' may produce 'NullPointerException'

How to solve this?

@Geolykt
Copy link
Contributor

Geolykt commented Sep 30, 2023

ALWAYS get the service provider lazily - that is as late as possible, but preferably via https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/server/ServiceRegisterEvent.html.

If it is done eagerly you risk that the economy plugin hasn't been initialized yet which would necessarily blow up your plugin.

However this approach doesn't guard against the event where there is no economy plugin - at which point you just have to roll the dice and decide what you do from there (either do nothing and crash with a NPE, disable plugin when no eco plugin is active or disable certain functionalities of your plugin if the eco plugin is absent)

@Huh-DIETHGOD
Copy link
Author

But there is XConomy plugin

@Geolykt
Copy link
Contributor

Geolykt commented Sep 30, 2023

This is an issue tracker, not a help forum.
This is not an issue with Vault.

I already said that the fix is to obtain services lazily as you can never be certain when the plugins register their economies.
The most basic solution is to register stuff on the 1st tick. BUT NEVER EVER OBTAIN THE SERVICE PROVIDER IN YOUR ONENABLE() OR CONSTURCTOR

@Huh-DIETHGOD
Copy link
Author

ok ty

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

No branches or pull requests

2 participants