Skip to content

Fix bad FunctionRegistry#remove logic #8015

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

Merged
merged 2 commits into from
Jul 13, 2025

Conversation

Efnilite
Copy link
Member

@Efnilite Efnilite commented Jul 8, 2025

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 old remove 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

@Efnilite Efnilite requested a review from a team as a code owner July 8, 2025 22:35
@Efnilite Efnilite added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. 2.12 Targeting a 2.12.X version release. Project ID: 7 labels Jul 8, 2025
@Efnilite Efnilite requested review from Burbulinis and TheMug06 and removed request for a team July 8, 2025 22:35
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label Jul 8, 2025
@skriptlang-automation skriptlang-automation bot added feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. and removed needs reviews A PR that needs additional reviews labels Jul 9, 2025
@sovdeeth sovdeeth merged commit 1a2bb40 into dev/feature Jul 13, 2025
6 of 7 checks passed
@skriptlang-automation skriptlang-automation bot added completed The issue has been fully resolved and the change will be in the next Skript update. and removed feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. labels Jul 13, 2025
@Efnilite Efnilite deleted the feature/fix-function-reloading branch July 14, 2025 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.12 Targeting a 2.12.X version release. Project ID: 7 bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants