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

Fix missing null checks for some Nullables #1710

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/java/gregtech/api/recipes/GTRecipeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static <R extends RecipeBuilder<R>> boolean removeRecipesByInputs(RecipeM
}
}

boolean wasRemoved = map.removeRecipe(map.findRecipe(Long.MAX_VALUE, itemIn, fluidIn));
Recipe recipeFound = map.findRecipe(Long.MAX_VALUE, itemIn, fluidIn);
boolean wasRemoved = recipeFound != null && map.removeRecipe(recipeFound);
if (ConfigHolder.misc.debug) {
if (wasRemoved)
GTLog.logger.info("Removed Recipe for inputs: Items: {} Fluids: {}", itemNames, fluidNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import gregtech.api.util.GTLog;

import javax.annotation.Nullable;
import java.util.Objects;

/**
Expand All @@ -18,6 +19,7 @@ public static NBTCondition create(NBTTagType tagType, String nbtKey, Object valu
return new NBTCondition(tagType, nbtKey, value);
}

@Nullable
public final NBTTagType tagType;
public final String nbtKey;
public final Object value;
Expand All @@ -28,6 +30,7 @@ private NBTCondition() {
this.value = null;
}

@SuppressWarnings("NullableProblems")
protected NBTCondition(NBTTagType tagType, String nbtKey, Object value) {
this.tagType = tagType;
this.nbtKey = nbtKey;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/**
* This class is used to match NBT tags. Used to match a MapItemStackNBTIngredient NBT tag to a given NBT tag value.
*/
@SuppressWarnings("unused")
public interface NBTMatcher {

static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
Expand All @@ -29,6 +30,9 @@ static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
* Return true if tag has an entry where the value is less than the condition's value
*/
NBTMatcher LESS_THAN = (tag, condition) -> {
if (condition == null || condition.tagType == null) {
return false;
}
if (hasKey(tag, condition.nbtKey, condition.tagType.typeId)) {
if (NBTTagType.isNumeric(condition.tagType)) {
return tag.getLong(condition.nbtKey) < (long) condition.value;
Expand All @@ -41,6 +45,9 @@ static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
* Return true if tag has an entry where the value is less than or equal to the condition's value
*/
NBTMatcher LESS_THAN_OR_EQUAL_TO = (tag, condition) -> {
if (condition == null || condition.tagType == null) {
return false;
}
if (hasKey(tag, condition.nbtKey, condition.tagType.typeId)) {
if (NBTTagType.isNumeric(condition.tagType)) {
return tag.getLong(condition.nbtKey) <= (long) condition.value;
Expand All @@ -53,6 +60,9 @@ static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
* Return true if tag has an entry where the value is greater than the condition's value
*/
NBTMatcher GREATER_THAN = (tag, condition) -> {
if (condition == null || condition.tagType == null) {
return false;
}
if (hasKey(tag, condition.nbtKey, condition.tagType.typeId)) {
if (NBTTagType.isNumeric(condition.tagType)) {
return tag.getLong(condition.nbtKey) > (long) condition.value;
Expand All @@ -65,6 +75,9 @@ static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
* Return true if tag has an entry where the value is greater than or equal to the condition's value
*/
NBTMatcher GREATER_THAN_OR_EQUAL_TO = (tag, condition) -> {
if (condition == null || condition.tagType == null) {
return false;
}
if (hasKey(tag, condition.nbtKey, condition.tagType.typeId)) {
if (NBTTagType.isNumeric(condition.tagType)) {
return tag.getLong(condition.nbtKey) >= (long) condition.value;
Expand All @@ -77,6 +90,9 @@ static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
* Return true if tag has an entry where the value is equal to the condition's value
*/
NBTMatcher EQUAL_TO = (tag, condition) -> {
if (condition == null || condition.tagType == null) {
return false;
}
if (hasKey(tag, condition.nbtKey, condition.tagType.typeId)) {
if (NBTTagType.isNumeric(condition.tagType)) {
return tag.getLong(condition.nbtKey) == (long) condition.value;
Expand Down Expand Up @@ -107,7 +123,7 @@ static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
* Return true if NBT isn't present or the value matches with the default value in the tag.
*/
NBTMatcher NOT_PRESENT_OR_DEFAULT = (tag, condition) -> {
if (tag == null) {
if (tag == null || condition == null || condition.tagType == null) {
return true;
}
if (NBTTagType.isNumeric(condition.tagType)) {
Expand Down Expand Up @@ -138,7 +154,7 @@ static boolean hasKey(NBTTagCompound tag, String key, int tagType) {
* Return true if NBT isn't present or is the provided key is present
*/
NBTMatcher NOT_PRESENT_OR_HAS_KEY = (tag, condition) -> {
if (tag == null) {
if (tag == null || condition == null || condition.tagType == null) {
return true;
}

Expand Down