Large arrays (~100+ elements) are not properly typed
@Jonathing is already working on this.
Since Jan 14, 2025.
Assessment
This issue has not been assessed yet.
Description
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.
- Dominant language
- Java
- Stars
- 39
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MinecraftForge/coremods
-
MinecraftForge/coremods#74 · 1 assignee ·
-
MinecraftForge/coremods#72 · 1 assignee ·
All issues in MinecraftForge/coremods
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
objectionary/jeo-maven-plugin#1811 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
hiero-ledger/hiero-block-node#3693 ·
-
area/dependencies kind/cve severity/critical source/scan-dependencies status/triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
proposal
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
beemdevelopment/Aegis#1840 ·