Unloading a script throws an UnsupportedOperationException
bluelhf opened this issue · 1 comments
Describe the bug
When a script containing events is unloaded, an UnsupportedOperationException is thrown by sun.misc.Unsafe, as ByteSkript attempts to acquire the field offset on a record class, specifically InvokingScriptRunner.
To Reproduce
Steps to reproduce the behaviour:
- Unload a script that contains an event using Skript#unloadScript(Script)
- See error
Expected behavior
The script should be unloaded without errors.
Errors
Caused by: java.lang.UnsupportedOperationException: can't get field offset on a record class: private final java.lang.Class org.byteskript.skript.runtime.internal.InvokingScriptRunner.owner
at jdk.unsupported/sun.misc.Unsafe.objectFieldOffset(Unsafe.java:648)
at BSFP-0.1.0-dev-all.jar//org.byteskript.skript.runtime.UnsafeAccessor.graveyard(UnsafeAccessor.java:48)
at BSFP-0.1.0-dev-all.jar//org.byteskript.skript.runtime.Skript.unloadScript(Skript.java:731)
at BSFP-0.1.0-dev-all.jar//blue.lhf.bsfp.BSFP.loadScript(BSFP.java:115)
at BSFP-0.1.0-dev-all.jar//blue.lhf.bsfp.BSFP.loadScriptTree(BSFP.java:151)
at BSFP-0.1.0-dev-all.jar//blue.lhf.bsfp.BSFP.lambda$loadScriptTreeAsync$7(BSFP.java:187)
at BSFP-0.1.0-dev-all.jar//blue.lhf.bsfp.util.MayThrow$Supplier.get(MayThrow.java:10)
Additional context
I'm running ByteSkript v1.0.24. Additionally, this issue can be solved by, for example, checking if the object being graveyarded is an instance of Record
in org.byteskript.skript.runtime.UnsafeAccessor.graveyard(Object)
I'll look into it, this isn't a major priority since unloading a script doesn't actually do anything other than free up the namespace.
If you're looking to make a mass-reloader I'd suggest simply creating a new Skript instance instead, which will reset all of the resources and prevent any graveyarding problems.