fix(D-01): compact constructor defaults null componentConfigs to empty (RISK-004)

Add compact constructor to DataDrivenItemDefinition that defaults null
componentConfigs to Map.of(). This makes the field guaranteed non-null,
allowing removal of null checks in hasComponent() and
DataDrivenItemRegistry.buildComponentHolders().
This commit is contained in:
NotEvil
2026-04-14 02:29:25 +02:00
parent 3a81bb6e12
commit bfcc20d242
2 changed files with 12 additions and 9 deletions

View File

@@ -105,8 +105,13 @@ public record DataDrivenItemDefinition(
Map<ComponentType, JsonObject> componentConfigs Map<ComponentType, JsonObject> componentConfigs
) { ) {
/** Compact constructor: default null componentConfigs to empty immutable map. */
public DataDrivenItemDefinition {
if (componentConfigs == null) componentConfigs = Map.of();
}
/** Check whether this definition declares a given component type. */ /** Check whether this definition declares a given component type. */
public boolean hasComponent(ComponentType type) { public boolean hasComponent(ComponentType type) {
return componentConfigs != null && componentConfigs.containsKey(type); return componentConfigs.containsKey(type);
} }
} }

View File

@@ -185,14 +185,12 @@ public final class DataDrivenItemRegistry {
DataDrivenItemDefinition def = entry.getValue(); DataDrivenItemDefinition def = entry.getValue();
Map<ComponentType, IItemComponent> components = Map<ComponentType, IItemComponent> components =
new EnumMap<>(ComponentType.class); new EnumMap<>(ComponentType.class);
if (def.componentConfigs() != null) { for (Map.Entry<ComponentType, JsonObject> compEntry :
for (Map.Entry<ComponentType, JsonObject> compEntry : def.componentConfigs().entrySet()) {
def.componentConfigs().entrySet()) { components.put(
components.put( compEntry.getKey(),
compEntry.getKey(), compEntry.getKey().create(compEntry.getValue())
compEntry.getKey().create(compEntry.getValue()) );
);
}
} }
holders.put( holders.put(
entry.getKey(), entry.getKey(),