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

Large arrays (~100+ elements) are not properly typed #68

Open
Jonathing opened this issue Nov 7, 2024 · 0 comments
Open

Large arrays (~100+ elements) are not properly typed #68

Jonathing opened this issue Nov 7, 2024 · 0 comments

Comments

@Jonathing
Copy link
Member

Jonathing commented Nov 7, 2024

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:

const list = ASMAPI.listOf();
list.add(node1);
list.add(node2);
// ...

However, another workaround is to use Java.to() to convert the entire array into your desired type. For example:

method.instructions = ASMAPI.listOf(Java.to([
    // ...
], Java.type('org.objectweb.asm.tree.AbstractInsnNode[]')));

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 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.

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

1 participant