Creating empty function in zenClass causes ArrayIndexOutOfBoundsException: -1
Bulldog83 opened this issue · 5 comments
Issue Description:
I'm using in my scripts zenClasses and found the one problem. Сreating an empty function in the zenClass causes ArrayIndexOutOfBoundsException: -1 on script load.
zenClass ClassName {
function funcName() {}
}
Affected Versions (Do not use "latest"):
- Minecraft: 1.12.2
- Forge: 14.23.4.2747
- Crafttweaker: 4.1.9
I've made it only with one script, to show:
[PREINITIALIZATION][SERVER][INFO] Current loaders after merging: [[preinit]]
[PREINITIALIZATION][SERVER][INFO] Loading scripts for loader with names [preinit]
[PREINITIALIZATION][SERVER][INFO] [preinit | SIDE_SERVER]: Skipping file {[1300:crafttweaker]: Disabling.class.zs} as we are currently loading with a different loader
[PREINITIALIZATION][SERVER][INFO] Completed script loading in: 2ms
[INITIALIZATION][SERVER][INFO] CraftTweaker: Building registry
[INITIALIZATION][SERVER][INFO] CraftTweaker: Successfully built item registry
[INITIALIZATION][SERVER][INFO] Current loaders after merging: [[preinit], [recipeevent | crafttweaker]]
[INITIALIZATION][SERVER][INFO] Loading scripts for loader with names [crafttweaker | recipeevent]
[INITIALIZATION][SERVER][INFO] [crafttweaker | SIDE_SERVER]: Loading Script: {[1300:crafttweaker]: Disabling.class.zs}
[INITIALIZATION][SERVER][ERROR] [crafttweaker | SIDE_SERVER]: Error loading {[1300:crafttweaker]: Disabling.class.zs}: java.lang.ArrayIndexOutOfBoundsException: -1
java.lang.ArrayIndexOutOfBoundsException: -1
at stanhebben.zenscript.definitions.zenclasses.ParsedZenClassMethod.writeAll(ParsedZenClassMethod.java:107)
at stanhebben.zenscript.definitions.zenclasses.ParsedZenClass.writeMethods(ParsedZenClass.java:152)
at stanhebben.zenscript.definitions.zenclasses.ParsedZenClass.writeClass(ParsedZenClass.java:114)
at stanhebben.zenscript.ZenParsedFile.<init>(ZenParsedFile.java:142)
at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:186)
at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:101)
at crafttweaker.mc1120.events.CommonEventHandler.registerRecipes(CommonEventHandler.java:68)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_22_CommonEventHandler_registerRecipes_Register.invoke(.dynamic)
at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90)
at net.minecraftforge.fml.common.eventhandler.EventBus$1.invoke(EventBus.java:144)
at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182)
at net.minecraftforge.registries.GameData.fireRegistryEvents(GameData.java:762)
at net.minecraftforge.common.crafting.CraftingHelper.loadRecipes(CraftingHelper.java:623)
at net.minecraftforge.fml.common.Loader.initializeMods(Loader.java:742)
at net.minecraftforge.fml.server.FMLServerHandler.finishServerLoading(FMLServerHandler.java:108)
at net.minecraftforge.fml.common.FMLCommonHandler.onServerStarted(FMLCommonHandler.java:337)
at net.minecraft.server.dedicated.DedicatedServer.func_71197_b(DedicatedServer.java:219)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:486)
at java.lang.Thread.run(Unknown Source)
[INITIALIZATION][SERVER][INFO] Completed script loading in: 243ms
Script:
#priority 1300
import crafttweaker.item.IItemStack;
import crafttweaker.oredict.IOreDictEntry;
zenClass CDisabling {
var removedItems as IItemStack[];
var removedNames as string[];
zenConstructor() {
removedItems = [];
removedNames = [];
}
function markForRemove(item as IItemStack) {
val clear_item = item.hasTag ? item.definition.makeStack() : item;
if(!isMarked(clear_item)) {
removedItems += clear_item;
recipes.remove(clear_item);
}
}
function markForRemove(name as string) {
if(!isMarked(name)) {
removedNames += name;
recipes.removeByRegex(name);
}
}
function markForRemove(ore as IOreDictEntry) {
for item in ore.items {
markForRemove(item);
}
}
function isMarked(name as string) as bool {
return removedNames in name;
}
function isMarked(item as IItemStack) as bool {
return removedItems in item;
}
function recipesRemove() {}
}
Issue is the empty method.
We rely on there being at least one statement in a method (since there's no extensions or abstract methods, it never crossed my mind that there could be a case where someone would have an empty method body)
There was code in the method, but when I changed the logic of the class, I commented out it and received the exception.