fix: Null-Sicherheitswarnungen bei eigenen Typen behoben

This commit is contained in:
Sven committed 2026-11-10 17:07:19 +01:00
1 parent a839096582
commit 850b1e3199
2 files changed
+13 -7

No files matched your search

@@ -307,7 +307,7 @@ public class BlockTypeRegistry {
public synchronized int nextCustomTaskType(Collection<Integer> reserved) { public synchronized int nextCustomTaskType(Collection<Integer> reserved) {
var occupied = new HashSet<>(reserved); var occupied = new HashSet<>(reserved);
types.values().forEach(type -> occupied.add(type.taskType())); types.values().forEach(type -> occupied.add(type.taskType()));
int highest = occupied.stream().mapToInt(Integer::intValue).max().orElse(CUSTOM_TYPE_START - 1); int highest = occupied.stream().mapToInt(value -> value.intValue()).max().orElse(CUSTOM_TYPE_START - 1);
int next = highest < Integer.MAX_VALUE - 1 ? Math.max(CUSTOM_TYPE_START, highest + 1) : CUSTOM_TYPE_START; int next = highest < Integer.MAX_VALUE - 1 ? Math.max(CUSTOM_TYPE_START, highest + 1) : CUSTOM_TYPE_START;
while (occupied.contains(next)) next++; while (occupied.contains(next)) next++;
return next; return next;
@@ -48,7 +48,9 @@ public final class CustomTypeValidator {
} }
private static void validateProperties(JsonNode properties, BlockType base) { private static void validateProperties(JsonNode properties, BlockType base) {
require(properties != null && properties.isArray(), "properties must be an array"); if (properties == null || !properties.isArray()) {
throw new IllegalArgumentException("properties must be an array");
}
require(properties.size() == base.properties().size(), "Properties must match the base type"); require(properties.size() == base.properties().size(), "Properties must match the base type");
Set<String> ids = new HashSet<>(); Set<String> ids = new HashSet<>();
for (JsonNode property : properties) { for (JsonNode property : properties) {
@@ -65,7 +67,9 @@ public final class CustomTypeValidator {
} }
private static void validateDefault(JsonNode value, PropertyType type) { private static void validateDefault(JsonNode value, PropertyType type) {
require(value != null, "defaultValue is required"); if (value == null) {
throw new IllegalArgumentException("defaultValue is required");
}
// Leere Vorgaben sind erlaubt; die Eingabefelder behandeln sie wie einen leeren Wert. // Leere Vorgaben sind erlaubt; die Eingabefelder behandeln sie wie einen leeren Wert.
if (value.isNull()) { if (value.isNull()) {
return; return;
@@ -100,15 +104,17 @@ public final class CustomTypeValidator {
private static String text(JsonNode object, String field, boolean allowBlank) { private static String text(JsonNode object, String field, boolean allowBlank) {
JsonNode value = object.get(field); JsonNode value = object.get(field);
require(value != null && value.isTextual() && (allowBlank || !value.textValue().isBlank()), if (value == null || !value.isTextual() || (!allowBlank && value.textValue().isBlank())) {
field + " must be a string" + (allowBlank ? "" : " and not blank")); throw new IllegalArgumentException(field + " must be a string" + (allowBlank ? "" : " and not blank"));
}
return value.textValue(); return value.textValue();
} }
private static int integer(JsonNode object, String field) { private static int integer(JsonNode object, String field) {
JsonNode value = object.get(field); JsonNode value = object.get(field);
require(value != null && value.isIntegralNumber() && value.canConvertToInt(), if (value == null || !value.isIntegralNumber() || !value.canConvertToInt()) {
field + " must be an integer"); throw new IllegalArgumentException(field + " must be an integer");
}
return value.intValue(); return value.intValue();
} }