CraftTweaker

CraftTweaker

151M Downloads

Arrays containing NULL elements will cause `has` operator to fail

DBotThePony opened this issue ยท 1 comments

commented

Issue Description:

If you try to array has thing in if statement, and array contains null elements, you will get java.lang.NullPointerException

Script used

var rubber = <techguns:itemshared:56>;

for recipe in recipes.all {
	var ingredients = recipe.ingredients1D;

	if (ingredients has rubber) {
		print(recipe.fullResourceDomain);
	}
}

Workaround:

var rubber = <techguns:itemshared:56>;

for recipe in recipes.all {
	var ingredients = recipe.ingredients1D;

	var valid = true;

	for ing in ingredients {
		if (isNull(ing)) {
			valid = false;
			break;
		}
	}

	if (valid) {
		if (ingredients has rubber) {
			print(recipe.fullResourceDomain);
		}
	}
}

crafttweaker.log file

[INITIALIZATION][CLIENT][ERROR] [crafttweaker]: Error executing {[0:crafttweaker]: techguns-community-edition.zs}: null
java.lang.NullPointerException
	at stanhebben.zenscript.util.ArrayUtil.contains(ArrayUtil.java:73)
	at Techguns-community-edition.__script__(techguns-community-edition.zs:25)
	at __ZenMain__.run(Techguns-community-edition)
	at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:174)
	at crafttweaker.runtime.CrTTweaker.loadScript(CrTTweaker.java:68)
	at crafttweaker.runtime.CrTTweaker.load(CrTTweaker.java:62)
	at crafttweaker.CrafttweakerImplementationAPI.load(CrafttweakerImplementationAPI.java:115)
	at crafttweaker.mc1120.events.CommonEventHandler.registerRecipes(CommonEventHandler.java:55)

Affected Versions:

  • Minecraft: 1.12.2
  • Forge: Build 2796
  • Crafttweaker: 4.1.9
  • Using a server: no
commented

@jaredlll08
Could you replace this
https://github.com/kindlich/ZenScript/blob/master/src/main/java/stanhebben/zenscript/util/ArrayUtil.java#L73
With an Objects.equals(item, toCheck) call?

Don't have an IDE currently and I don't want to start writing actal code using only GH mobile lol