fix: Null-Sicherheitswarnungen bei eigenen Typen behoben
This commit is contained in:
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) {
|
||||
var occupied = new HashSet<>(reserved);
|
||||
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;
|
||||
while (occupied.contains(next)) next++;
|
||||
return next;
|
||||
|
||||
@@ -48,7 +48,9 @@ public final class CustomTypeValidator {
|
||||
}
|
||||
|
||||
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");
|
||||
Set<String> ids = new HashSet<>();
|
||||
for (JsonNode property : properties) {
|
||||
@@ -65,7 +67,9 @@ public final class CustomTypeValidator {
|
||||
}
|
||||
|
||||
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.
|
||||
if (value.isNull()) {
|
||||
return;
|
||||
@@ -100,15 +104,17 @@ public final class CustomTypeValidator {
|
||||
|
||||
private static String text(JsonNode object, String field, boolean allowBlank) {
|
||||
JsonNode value = object.get(field);
|
||||
require(value != null && value.isTextual() && (allowBlank || !value.textValue().isBlank()),
|
||||
field + " must be a string" + (allowBlank ? "" : " and not blank"));
|
||||
if (value == null || !value.isTextual() || (!allowBlank && value.textValue().isBlank())) {
|
||||
throw new IllegalArgumentException(field + " must be a string" + (allowBlank ? "" : " and not blank"));
|
||||
}
|
||||
return value.textValue();
|
||||
}
|
||||
|
||||
private static int integer(JsonNode object, String field) {
|
||||
JsonNode value = object.get(field);
|
||||
require(value != null && value.isIntegralNumber() && value.canConvertToInt(),
|
||||
field + " must be an integer");
|
||||
if (value == null || !value.isIntegralNumber() || !value.canConvertToInt()) {
|
||||
throw new IllegalArgumentException(field + " must be an integer");
|
||||
}
|
||||
return value.intValue();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user