Fix bad FunctionRegistry#remove logic #8015
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Bug explanation
When removing functions from the FunctionRegistry, the
remove
method would attempt to get the namespace of the function being removed. To do this, it uses the script of the signature of the function. Functions registered in Java have no script, but functions registered in Skript do.Therefore, if a function was previously registered and unregistered, it would leave an empty namespace in the
namespaces
map. The oldremove
logic would then incorrectly assume that this is the namespace of the function being removed, since the Skript-based function has a non-null script, and then not do anything.Since all unit tests are made using Java, remove would work fine for Java functions, as the namespace is always null.
Scope enforcement
Also changes the register methods to enforce specifying exactly which namespace to register in, which increases clarity in where functions actually end up. Therefore, you are no longer able to register a local function to the global namespace by setting null as the namespace, and you are no longer able to register a global function to a local namespace by specifying a namespace in the
Registry#register(String namespace, String name, Class<?> args...)
arguments.Solution
Update the code to check whether the signature is local to determine which namespace to use.
Testing Completed
Added a unit test which recreates the exact scenario in which this error would occur.
Supporting Information
No breaking changes as FunctionRegistry is package-protected.
Completes: none
Related: none