You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually a Nashorn bug, but I'd like to workaround it in CoreMods 5.3. Essentially, large arrays (either created with [] or with varargs) are not converted to the required type, but rather to Object[]. This is a problem particularly for ASMAPI.listOf(), which uses a varargs signature of ([Lorg/objectweb/asm/tree/AbstractInsnNode;). When the coremod script is evaluated by Nashorn, the script fails with a ClassCastException: cannot cast [Ljava/lang/Object;] to org/objectweb/asm/tree/AbstractInsnNode.
Workarounds
The easiest way to workaround this is to manually add each node to a list. For example:
A solution to workaround this in CoreMods would be to create a sister method ASMAPI.listOf(Object... nodes) which accepts varargs object. Though, it might have a performance impact due to needing to cast each node to AbstractInsnNode. We can realistically skip the instanceof check since coremods should never attempt to add other objects that aren't nodes to an InsnList.
The text was updated successfully, but these errors were encountered:
This is actually a Nashorn bug, but I'd like to workaround it in CoreMods 5.3. Essentially, large arrays (either created with
[]
or with varargs) are not converted to the required type, but rather toObject[]
. This is a problem particularly forASMAPI.listOf()
, which uses a varargs signature of([Lorg/objectweb/asm/tree/AbstractInsnNode;)
. When the coremod script is evaluated by Nashorn, the script fails with aClassCastException: cannot cast [Ljava/lang/Object;] to org/objectweb/asm/tree/AbstractInsnNode
.Workarounds
The easiest way to workaround this is to manually add each node to a list. For example:
However, another workaround is to use
Java.to()
to convert the entire array into your desired type. For example:Solution(?)
A solution to workaround this in CoreMods would be to create a sister method
ASMAPI.listOf(Object... nodes)
which accepts varargs object. Though, it might have a performance impact due to needing to cast each node toAbstractInsnNode
. We can realistically skip the instanceof check since coremods should never attempt to add other objects that aren't nodes to anInsnList
.The text was updated successfully, but these errors were encountered: